Sitelet https://github.com/python/cpython/issues/100272#issue-1498705665
Skip to content

JSON does not preserve the order of OrderedDict #100272

Description

@serhiy-storchaka

#95385 caused a regression in JSON serialization of OrderedDict when use the C implementation.

>>> import collections, json
>>> od = collections.OrderedDict(a=1, b=2)
>>> od.move_to_end('a')
>>> od
OrderedDict([('b', 2), ('a', 1)])
>>> json.dumps(od)
'{"a": 1, "b": 2}'

With the pure Python implementation, as well as in older Pythons, you get '{"b": 2, "a": 1}'.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Dec 15, 2022
  2. added a commit that references this issue on Dec 19, 2022
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

    3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions