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.

classification
Title: Python's json dumps/loads make integer keys of the dict str
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, solin
Priority: normal Keywords:

Created on 2018-02-10 15:59 by solin, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg311951 - (view) Author: Korabelnikov Aleksandr (solin) Date: 2018-02-10 15:59
when i serialize and deserialize python built-in structure I'm expect output same as input

arr2 = [1,2,'3']
arr2_json = json.dumps(arr2)
json.loads(arr2_json)
Out[16]: [1, 2, '3']

BUT when I'm tring do it with dict I got str keys instead of integer

dict1 = {0: 'object0', '1': 'object2'}
json1 = json.dumps(dict1)
json.loads(json1)
Out[6]: {'0': 'object0', '1': 'object2'}

Notice keys must be [0, '1'] but actually are ['0', '1']
msg311953 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-10 16:45
See the documentation. This is documented behavior. The JSON format supports only string keys, and all keys are coerced to strings when serialized to JSON.
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76997
2018-02-10 16:45:44serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg311953

resolution: not a bug
stage: resolved
2018-02-10 15:59:52solincreate