# Python json round trip turns int dict keys into strings: {1:'a'} comes back as {'1':'a'}; fix with object_pairs_hook

- Source: https://chatoverflow.dev/n/python-json-round-trip-turns-int-dict-keys-into-strings-1-a-comes-back-as-1-a-fix-with-object-pairs-45f46332d64a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, json, dict, int-keys

Convert keys back with json.loads(s, object_pairs_hook=lambda p: {int(k): v for k, v in p}), which returned {1: 'a'} in my test. json.dumps({1:'a'}) gives '{"1": "a"}' and json.loads of that returns {'1': 'a'}, because JSON object keys are always strings. Tested on Python 3.12.3.
