JSON Sort Keys
Sort JSON keys recursively to make files diff cleanly and compare reliably.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
Object key order is not semantic
The JSON specification treats objects as unordered, so two documents with the same pairs in different order are equivalent. Most parsers preserve insertion order in practice, which means a serialiser that emits keys in a different order produces a file that diffs as entirely changed while being identical in meaning.
This is why sorting matters in version control
An API response or a config file regenerated by a tool with non-deterministic key order creates enormous diffs with no real changes, burying the one line that actually differs. Sorting keys canonically before committing makes diffs reflect substance. The same applies to comparing two environments' configuration, where unsorted output makes a genuine difference impossible to spot.
Arrays must not be reordered
Array order is semantic in JSON. A sorter must recurse into arrays to sort the objects inside them while leaving the array sequence untouched. A tool that sorts array elements corrupts the data, and it is a real failure mode worth checking before trusting output.
Canonical forms go further
Where JSON is signed or hashed, key order alone is not enough — whitespace, number formatting, and Unicode escaping all have to be fixed too. JCS, defined in RFC 8785, specifies a full canonicalisation for exactly this purpose. Sorting keys is a useful convenience; it is not a canonical form.
Duplicate keys are undefined behaviour
The specification does not forbid them, and parsers differ on whether the first or last wins. Sorting surfaces duplicates by placing them adjacent, which makes an otherwise invisible ambiguity obvious.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
Does JSON key order matter?
Not semantically — the specification treats objects as unordered. It matters practically, because reordered keys produce diffs that look like total rewrites.
Why sort JSON keys before committing?
So diffs reflect real changes. A regenerated file with non-deterministic key order buries the one meaningful line in a diff of everything.
Should arrays be sorted too?
No. Array order is semantic in JSON. A sorter should recurse into arrays to sort objects inside them while leaving the sequence untouched.
Is sorting keys enough for signing JSON?
No. Signing needs full canonicalisation covering whitespace, number formatting and Unicode escaping, which RFC 8785 specifies as JCS.
Privacy & Security
All processing happens locally in your browser — nothing is uploaded.
How to Use
Paste JSON; its keys are sorted alphabetically at every level.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.