quinnj / JSON3.jl

Other
214 stars 47 forks source link

Preserving types #194

Closed mo8it closed 2 years ago

mo8it commented 2 years ago

If a float of the form 2.0 is written with pretty then it is converted to int!

julia> JSON3.pretty((a = 2.0, b = 2)) { "a": 2, "b": 2 }

julia> JSON3.write((a = 2.0, b = 2)) "{\"a\":2.0,\"b\":2}"

As seen above, write() does preserve the float type while writing, but if you read it, the type is lost:

julia> JSON3.read(JSON3.write((a = 2.0, b = 2))) JSON3.Object{Base.CodeUnits{UInt8, String}, Vector{UInt64}} with 2 entries: :a => 2 :b => 2

There has to be an option to not convert floats with 0 after the decimal point to int when reading or writing.

JSON3 v1.9.2

mo8it commented 2 years ago

https://github.com/quinnj/JSON3.jl/issues/198