Skip to content

OrderedDict output changes on 1.4.0 -> 1.5.0 #447

@penelopeysm

Description

@penelopeysm

On JSON.jl 1.4.0 and 1.5.0 the serialisation of OrderedDict changes:

julia> d = OrderedDict(:b => 2, :a => 1)
OrderedDict{Symbol, Int64} with 2 entries:
  :b => 2
  :a => 1

julia> JSON.json(d) # 1.4.0
"{\"b\":2,\"a\":1}"

julia> JSON.json(d) # 1.5.0
"{\"a\":1,\"b\":2}"

That means that roundtrip serialisation/deserialisation is no longer faithful.

I can see that this is a result of #442 and I welcome that added API, but the problem is that the new default leads to different semantics for containers whose iteration order is known. While one could argue that the serialisation order was never really guaranteed, the existing semantics in JSON.jl <= 1.4 are that it follows the iteration order, and I'd be surprised if I was the only user who relied on this. From my perspective this is effectively a breaking change.

In fact, Claude's writeup on #442 says that

JSON.Object is exempted because it was specifically designed for insertion-order preservation — users who choose Object have explicitly opted into a particular key ordering.

But that probably isn't the only collection where users have "explicitly opted into a particular key ordering". I'm using OrderedDict right now, but there may well be more stuff out there.

Would there be a more conservative way of making the same change, e.g. retaining the old behaviour as the default, and forcing the user to specify sort_keys=True if they actually want it to be sorted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions