Skip to content

Serialization of Pair and Vector{Pair} returns unexpected result #321

Description

@hhaensel

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions