Consider this snippet:
>>> import json
>>> a = {1:'1'}
>>> json_a = json.dumps(a)
>>> json.loads(json_a)
{'1': '1'}
My attempt was to pass a Python dict to json.dumps(), and then use json.loads() to get it back. But that doesn't happen, probably because JSON alays considers keys as strings.
Is there any other way I can retain the original key types?
We can use
str(value)in place ofjson.dumps(value), andast.literal_eval()in place ofjson.loads()Just posted as an initial solution, expecting a more sophisticated one.