API Reference

JSON parser

YYJSON.ParserJSON.parse_jsonFunction
parse_json(x::String; kw...)
parse_json(x::Vector{UInt8}; kw...)

Parse a JSON string x (or vector of UInt8) into a dictionary.

Keyword arguments

  • dict_type::Type{D} = Dict{String,Any}: Defines the type of dictionary into which objects will be parsed.
  • null::Union{Nothing,Missing} = nothing: Null value.
  • in_situ::Bool: This option allows the reader to modify and use the input data to store string values, which can slightly improve reading speed.
  • number_as_raw::Bool: Read all numbers as raw strings without parsing.
  • bignum_as_raw::Bool: Read big numbers as raw strings.
  • stop_when_done::Bool: Stop parsing when reaching the end of a JSON document instead of issues an error if there's additional content after it.
  • allow_comments::Bool: Allow C-style single line and multiple line comments.
  • allow_inf_and_nan::Bool: Allow nan/inf` number or case-insensitive literal.
  • allow_invalid_unicode::Bool: Allow reading invalid unicode when parsing string values.
  • allow_trailing_commas::Bool: Allow a single trailing comma at the end of an object or array.

Examples

julia> json = """{
           "str": "John Doe",
           "num": "30",
           "array": [1,2,{"a": 3, "b": null}],
           "bool": false,
           "obj" : {"a": 1, "b": null},
           "another": "key"
       }
       """;

julia> parse_json(json)
Dict{String, Any} with 6 entries:
  "another" => "key"
  "str"     => "John Doe"
  "obj"     => Dict{String, Any}("b"=>nothing, "a"=>1)
  "array"   => Any[1, 2, Dict{String, Any}("b"=>nothing, "a"=>3)]
  "num"     => "30"
  "bool"    => false
source
YYJSON.ParserJSON.open_jsonFunction
open_json(path::String; kw...)

Reads a JSON file from a given path and parse it into dictionary.

Keyword arguments

Similar to parse_json.

source
open_json(io::IO; kw...)

Reads a JSON file from a given io and parse it into dictionary.

Keyword arguments

Similar to parse_json.

source

JSON lazy parser

YYJSON.LazyJSON.LazyJSONDictType
LazyJSONDict <: AbstractDict{AbstractString,Any}

Represents a dictionary for a JSON object.

Fields

  • ptr::Ptr{YYJSONVal}: The object value pointer.
  • iter::YYJSONObjIter: The object iterator structure.
  • doc_ptr::Ptr{YYJSONDoc}: The JSON document pointer (non-null only for the root).
  • alc_ptr::Ptr{YYJSONAlc}: The dynamic allocator pointer (non-null only for the root).
  • freed::Bool: Flag indicating whether the document is freed.
source
YYJSON.LazyJSON.LazyJSONVectorType
LazyJSONVector <: AbstractVector{Any}

Represents a vector for a JSON array.

Fields

  • ptr::Ptr{YYJSONVal}: The array value pointer.
  • doc_ptr::Ptr{YYJSONDoc}: The JSON document pointer (non-null only for the root).
  • alc_ptr::Ptr{YYJSONAlc}: The dynamic allocator pointer (non-null only for the root).
  • freed::Bool: Flag indicating whether the document is freed.
source
YYJSON.LazyJSON.parse_lazy_jsonFunction
parse_lazy_json([f::Function], json::String; kw...)
parse_lazy_json([f::Function], json::Vector{UInt8}; kw...)

Parse a JSON string json (or vector of UInt8) into a LazyJSONDict or LazyJSONVector.

Note

When it's no longer needed, it should be closed with close or use do block syntax.

Keyword arguments

Similar to parse_json.

Examples

julia> json = """{
           "str": "John Doe",
           "num": "30",
           "array": [1,2,{"a": 3, "b": null}],
           "bool": false,
           "obj" : {"a": 1, "b": null},
           "another": "key"
       }
       """;

julia> parse_lazy_json(json)
LazyJSONDict with 6 entries:
  "str"     => "John Doe"
  "num"     => "30"
  "array"   => Any[1, 2, LazyJSONDict("a"=>3, "b"=>nothing)]
  "bool"    => false
  "obj"     => LazyJSONDict("a"=>1, "b"=>nothing)
  "another" => "key"
julia> json = """{
           "array": [1,2,3]
       }
       """;

array = []
parse_lazy_json(json) do data
    for value in data["array"]
        push!(array, value)
    end
end

julia> array
3-element Vector{Any}:
 1
 2
 3
source
YYJSON.LazyJSON.open_lazy_jsonFunction
open_lazy_json([f::Function], path::String; kw...)
open_lazy_json([f::Function], io::IO; kw...)

Reads a JSON file from a given path or io and parse it into a LazyJSONDict or LazyJSONVector.

Note

When it's no longer needed, it should be closed with close or use do block syntax.

Keyword arguments

Similar to parse_json.

source