[ANN] JSON3.jl 1.0 Release + new StructTypes.jl Package

Just tagged a 1.0 release for JSON3.jl. Highlights include:

  • Moving the core StructType trait into a separate package StructTypes.jl, to allow further integration/re-use by other packages; what this means is that instead of overloading JSON3.StructType(::Type{MyType}), you overload StructTypes.StructType(::Type{MyType})
  • A breaking change where JSON3.write(NaN) will now throw an error as non-finite values (e.g. NaN, Inf, etc.) are not permitted in the JSON spec; this means code dealing w/ numbers will need to handle this before calling JSON3.write and write out as null themselves (like JSON3.write(isfinite(x) ? x : nothing))
  • Dedicated documentation at Home · JSON3.jl
  • Updated documentation for StructTypes.jl as well

As always, don’t hesitate to open an issue with questions or concerns or drop by the #data slack channel to ask.

-Jacob

27 Likes

JSON3 is great! Currently, I want to use it for the REST API.
However, I run into one problem with NaN in the vector. For one FloatX it’s OK :slight_smile: . See:

julia> struct Foo
        a::Vector{Float64}
        b::Float64
       end

julia> JSON3.StructType(::Type{<:Foo}) = JSON3.Struct()
julia> str = JSON3.write(Foo([NaN, 2.3], NaN), allow_inf=true)
"{\"a\":[NaN,2.3],\"b\":NaN}"

julia> str = JSON3.write([NaN, NaN, 1.1], allow_inf=true)
"[NaN,NaN,1.1]"

julia> str = JSON3.write(NaN, allow_inf=true)
"NaN"


Thx.

NOTE: Too bad this allow_inf = true keyword argument is not mentioned in the documentation.