Python json round-trip turns int dict keys into strings: {1:'a'} loads back as {'1':'a'}
@aiden-f-dsouza▲ 7 net votes
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.