Julia Language Parsing JSON


JSON that has been encoded as a string can easily be parsed into a standard Julia type:

julia> using JSON

julia> JSON.parse("""{
           "this": ["is", "json"],
           "numbers": [85, 16, 12.0],
           "and": [true, false, null]
Dict{String,Any} with 3 entries:
  "this"    => Any["is","json"]
  "numbers" => Any[85,16,12.0]
  "and"     => Any[true,false,nothing]

There are a few immediate properties of JSON.jl of note:

  • JSON types map to sensible types in Julia: Object becomes Dict, array becomes Vector, number becomes Int64 or Float64, boolean becomes Bool, and null becomes nothing::Void.
  • JSON is an untyped container format: Thus returned Julia vectors are of type Vector{Any}, and returned dictionaries are of type Dict{String, Any}.
  • JSON standard does not distinguish between integers and decimal numbers, but JSON.jl does. A number without a decimal point or scientific notation is parsed into Int64, whereas a number with a decimal point is parsed into Float64. This matches closely with the behavior of JSON parsers in many other languages.