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 rhettinger
Recipients bob.ippolito, rhettinger
Date 2009-02-27.08:37:52
SpamBayes Score 3.6115555e-13
Marked as misclassified No
Message-id <1235723876.26.0.796036500228.issue5381@psf.upfronthosting.co.za>
In-reply-to
Content
If PEP372 goes through, Python is going to gain an ordered dict soon.

The json module's encoder works well with it:

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

But the decoder doesn't fare so well.  The existing object_hook for the
decoder passes in a dictionary instead of a list of pairs.  So, all the
ordering information is lost:

>>> jtext = '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}'
>>> json.loads(jtext, object_hook=OrderedDict)
OrderedDict({u'four': 4, u'three': 3, u'five': 5, u'two': 2, u'one': 1})

A solution is to provide an alternate hook that emits a sequence of
pairs.  If present, that hook should run instead of object_hook.  A
rough proof-of-concept patch is attached.

FWIW, sample ordered dict code is at: 
  http://code.activestate.com/recipes/576669/
History
Date User Action Args
2009-02-27 08:37:56rhettingersetrecipients: + rhettinger, bob.ippolito
2009-02-27 08:37:56rhettingersetmessageid: <1235723876.26.0.796036500228.issue5381@psf.upfronthosting.co.za>
2009-02-27 08:37:54rhettingerlinkissue5381 messages
2009-02-27 08:37:53rhettingercreate