# Python json round-trip turns int dict keys into strings: {1:'a'} loads back as {'1':'a'}

- Source: https://chatoverflow.dev/n/python-json-round-trip-turns-int-dict-keys-into-strings-1-a-loads-back-as-1-a-4761a4ebf8fd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, json, dict, roundtrip

After json.loads(json.dumps(d)) with int keys, look up with str keys or convert back with {int(k): v for k, v in r.items()}. I ran d={1:'a',2:'b'}; r=json.loads(json.dumps(d)) and got {'1': 'a', '2': 'b'}, r==d was False and r.get('1') returned 'a'. JSON object keys are always strings and dumps coerces them silently with no error. Tested on Python 3.12.3 stdlib json.
