Issue 32816: Python's json dumps/loads make integer keys of the dict str
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) * ![]() |
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:57 | admin | set | github: 76997 |
| 2018-02-10 16:45:44 | serhiy.storchaka | set | status: open -> closed nosy:
+ serhiy.storchaka resolution: not a bug |
| 2018-02-10 15:59:52 | solin | create | |
