JSON Sorter — Sort Keys Alphabetically
Sort every object's keys A→Z (or Z→A), recursively through the whole document. Arrays keep their order — only key order changes.
Why sort JSON keys?
JSON objects are officially unordered — but the text file you commit, diff and compare very much has an order. Two exports of the same data with different key order look completely different to diff, Git and your eyes. Sorting keys produces a canonical form: the same data always serializes to the same text.
- Clean diffs — config exports, API snapshots and fixtures stop producing noise when only the order moved.
- Easy comparison — sort two payloads, then any text-diff tool shows the real differences.
- Faster lookup — finding a key by eye in a 60-key object is much quicker alphabetically.
- Deduplication checks — canonical text makes "are these two documents identical?" a string comparison.
What the sorter deliberately leaves alone
Arrays are never reordered. Unlike object keys, array order is data — ["red","green"] and ["green","red"] are different values. The sorter recurses into array elements (objects inside arrays get their keys sorted) but the elements stay where they are. String values, numbers and everything else are untouched too: this is a formatting operation, not a data transformation.
Sorting order details
Keys are compared with locale-aware string comparison, so a < b as expected and international characters order sensibly. Sorting is applied at every nesting level in one pass. Pair it with the JSON Beautifier for fully canonical, review-ready files — or use Sort keys directly inside the main formatter.
Frequently asked questions
Does key order matter in JSON?
Per the standard, no — RFC 8259 defines objects as unordered collections, and no compliant consumer may depend on key order. In practice most parsers preserve insertion order, which is why sorting is safe and also why unsorted exports produce messy diffs.
Are arrays sorted too?
No, by design. Array order is meaningful data — reordering [1,2,3] would change the value. The sorter recurses into array elements to sort keys of objects inside them, but never moves the elements themselves.
Is the sort recursive?
Yes. Every object at every nesting depth gets its keys sorted in the same pass — including objects nested inside arrays inside objects.
Can sorted JSON break an application?
Only if the application violates the JSON standard by depending on key order (rare, but it exists in some legacy signature schemes). For canonical hashing schemes like JCS, key sorting is actually a requirement.
How do I compare two JSON documents with this?
Sort both with the same settings, then paste them into any text diff tool. Because both are now in canonical form, the diff shows only genuine data differences, not ordering noise.