quinnj / JSON3.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slight incompatibility between LazyJSON.Object and JSON3.write

ninjaaron opened this issue · comments

Hi! Thanks for JSON3 (and JSON2)!

julia> using LazyJSON, JSON3

julia> object = LazyJSON.value("""{"foo":"bar"}""")
LazyJSON.Object{Nothing,String} with 1 entry:
  "foo" => "bar"

julia> JSON3.write(object) |> println
{"\"foo\"":"bar"}

julia> JSON3.write(Dict("foo" => "bar")) |> println
{"foo":"bar"}

It's awesome that this even works at all, but as you can see, LazyJSON.Object keys somehow get extra quotes when printed. Since compatibility is already 99% there, it would be nice if this issue could be fixed. I don't know if the problem is on your end or LazyJSON's end, but I opened an issue over there as well.

Hmmm, let me look into it. Thanks for reporting.

Ok, looks like this is due to this definition; basically, LazyJSON.jl defines string(::JSON.Value) to mean "give me a SubString back into the original json for this value", which in the case of an object key, includes the quotes I guess. Personally, I think that's a poor definition since string(x) has a generally accepted meaning of "give me the stringified version of x". It looks like LazyJSON also defines a jsonstring, which seems like it would be a more appropriate function name for what string is currently doing.

Thanks for looking into it! I'll mention it on the issue on LazyJSON.