keys in JSON are not sorted, but ordered based on definition. This becomes apparent when iterating keys of an object. For example, in JavaScript, with an object literal:
x = { a: 0, b: 1 }
y = { b: 0, a: 1 }
for (var key in x) console.log(key)
for (var key in y) console.log(key)
for (var key in JSON.parse(JSON.stringify(x))) console.log(key)
for (var key in JSON.parse(JSON.stringify(y))) console.log(key)
prints
For example, I believe most JS JITs keep separate shapes for object with the same properties but defined in different orders.
keys in JSON are not sorted, but ordered based on definition. This becomes apparent when iterating keys of an object. For example, in JavaScript, with an object literal:
prints
For example, I believe most JS JITs keep separate shapes for object with the same properties but defined in different orders.