Numbers as dictionary keys possible with simplejson?

4 views
Skip to first unread message

Anton I. Sipos

unread,
Dec 14, 2010, 6:03:33 PM12/14/10
to simplejson-discuss
I'm trying to serialize the following data structure, that uses
integers as keys to a dictionary. In the result, the keys show up as
strings:

>>> simplejson.dumps({1:'foo', 2:'bar'})
'{"1": "foo", "2": "bar"}'

Which is the same result of this dictionary:

>>> simplejson.dumps({"1":'foo', "2":'bar'})
'{"1": "foo", "2": "bar"}'

Is there a way to get simplejson to serialize the keys as numbers? I'm
using simplejson 2.1.1.

Thanks.




Bob Ippolito

unread,
Dec 14, 2010, 8:12:20 PM12/14/10
to simplejso...@googlegroups.com
This is not possible because it is not permitted in the JSON spec.
Reply all
Reply to author
Forward
0 new messages