Message88335
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. |
|
Date |
User |
Action |
Args |
2009-05-26 07:00:45 | lehmannro | set | recipients:
+ lehmannro, rhettinger, wangchun |
2009-05-26 07:00:45 | lehmannro | set | messageid: <1243321245.04.0.550473291974.issue6105@psf.upfronthosting.co.za> |
2009-05-26 07:00:42 | lehmannro | link | issue6105 messages |
2009-05-26 07:00:41 | lehmannro | create | |
|