I was trying to serialize my objects in a way that I could read them in the external form and found jsonpickle. But it turns out that it converts my dictionary keys from integers to strings.
I noticed this thread on the problem using just the JSON package but I was hoping that jsonpickle would fix the problem. Are there any known workarounds? Alternatively is there a better text-mode serialization format to use for Python?
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>> a={}
>>> a[11]="eleventy"
>>> a[22]="twice that"
>>> a
{11: 'eleventy', 22: 'twice that'}
>>> import jsonpickle
>>> jstring=jsonpickle.encode(a)
>>> jstring
'{"22": "twice that", "11": "eleventy"}'
>>> b=jsonpickle.decode(jstring)
>>> b
{'22': 'twice that', '11': 'eleventy'}
>>>
Update: For short term my work around is to have parallel save functions -- one to pickle and one to jsonpickle. Since my objects are complex (circular references) I can't get away with something that can't handle that. My original requirement was to have a format that I could read in a text editor so I could detect problems with the logic so as long as regular pickel is reliable (it is) than that will do me for now. Someday I might want to have some other non-Python software eat this file so I would like to find a usable solution. XML format? The Python community doesn't seem to be that interested in serializing to XML. At least I haven't found a package that works as easily as pickle/jsonpickle does.