Serialization of Pair and Vector{Pair} returns unexpected result
From JSON3 I expected a Pair to be serialized as an Object, but I find:
julia> JSON3.write("message" => "Hello World!")
"{\"message\":\"Hello World!\"}"
julia> JSON.json("message" => "Hello World!")
"{\"first\":\"message\",\"second\":\"Hello World!\"}"
and
julia> JSON3.write(["message" => "Hello World!"])
"[{\"message\":\"Hello World!\"}]"
julia> JSON.json(["message" => "Hello World!"])
"[\"Hello World!\"]"
Is this behaviour by purpose?
I could solve the issue by defining
JSON.lower(p::Pair) = JSON.Object(Symbol(p.first) => p.second)
JSON.lower(::JSON.JSONStyle, pp::AbstractVector{<:Pair}) = JSON.Object(pp)
But I guess such lowering should be done rather in a private JSONStyle then?
@quinnj
This is behavior is breaking our migration from JSON3 to JSON v1 of GenieFramework. We could, of cause, eliminate that single call where our tests break, but end users may have setup their applications assuming that json of Pairs are Objects, as it used to be for both JSON 0.x and JSON3. We could as well do the lowering as mentioned above, but I expect that more users will be concerned sooner or later. What do you think? Concerning Vectors of Pairs it's not clear to me why we should expect an output of values without keys.
@quinnj what about the serialisation of a Pair?
It was fixed via https://github.com/JuliaServices/StructUtils.jl/pull/22