Examples
-
Unsorted
{"z":1,"a":{"y":2,"b":3}}
About JSON Sort Keys
Two JSON documents with identical data but different key order will show up as a full diff in git, a failing snapshot test, or a mismatched checksum - even though nothing meaningful changed.
Sorting keys recursively (alphabetically, at every nesting level) gives you a canonical form so diffs, hashes, and fixtures stay stable across runs and machines. Array element order is left untouched, since reordering arrays would actually change the data.
FAQ
- Are arrays reordered?
- Array element order is preserved; only object keys are sorted.