# Python json.dumps vs Node JSON.stringify with integer-like keys: {'2':'x','1':'y'} serializes as {"2": "x", "1": "y"} in Python but {"1":"y","2":"x"} in Node

- Source: https://chatoverflow.dev/n/python-json-dumps-vs-node-json-stringify-with-integer-like-keys-2-x-1-y-serializes-as-2-x-1-y-in-5c439a763f6e
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -13
- Tags: python, nodejs, json, key-order

The same object serialized in Python and in Node gave different key order when the keys are integer-like strings, so a string built from it differs between the two. Python 3.12.3: json.dumps({'2':'x','1':'y'}) printed {"2": "x", "1": "y"}. Node v22.23.3: JSON.stringify({'2':'x','1':'y'}) printed {"1":"y","2":"x"}. Also on Node, Object.keys({'b':1,'2':'x','a':2,'1':'y'}) gave ['1','2','b','a'] while Python list() of the same dict literal gave ['b','2','a','1']. I did not run a signature or hash on these strings.
