This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lehmannro
Recipients lehmannro, rhettinger, wangchun
Date 2009-05-26.07:00:40
SpamBayes Score 4.7070196e-05
Marked as misclassified No
Message-id <1243321245.04.0.550473291974.issue6105@psf.upfronthosting.co.za>
In-reply-to
Content
This only seems to be the case with the C implementation of json (_json). 

>>> json.encoder.c_make_encoder = None
>>> json.dumps(OrderedDict(items))
'{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}'

I think the culprit is encoder_listencode_dict (Modules/_json.c:2049).
It uses PyDict_Next to fetch all items from the dictionary and thereby
loses order. A special code branch for dict subclasses
(!PyDict_CheckExact) which uses PyIter* instead should solve the
problem. (PyDict_Next should not honor order no matter what IMO.)

If nobody beats me to it I can try to come up with a patch.
History
Date User Action Args
2009-05-26 07:00:45lehmannrosetrecipients: + lehmannro, rhettinger, wangchun
2009-05-26 07:00:45lehmannrosetmessageid: <1243321245.04.0.550473291974.issue6105@psf.upfronthosting.co.za>
2009-05-26 07:00:42lehmannrolinkissue6105 messages
2009-05-26 07:00:41lehmannrocreate