Sort JSON keys alphabetically
Runs locallyAlphabetise object keys at every level. Array order is left untouched.
JSON input
Result
Paste JSON on the left — the result appears here automatically.
About sorting JSON keys
How it works in 4 steps · 4 common use cases · 3 questions answered
About sorting JSON keys
How it works in 4 steps · 4 common use cases · 3 questions answered
How it works
- 1.Paste the JSON document you want reordered.
- 2.Choose ascending or descending order.
- 3.Every object is sorted, at every nesting level, while array order is left untouched.
- 4.Copy the result, or run the same tool on a second document to compare the two.
Common use cases
- •Making two payloads with the same data but different key order diff cleanly
- •Normalising a generated config before committing it, so future diffs stay small
- •Finding a key quickly in a large object by scanning alphabetically
- •Producing a stable form of a document to hash or snapshot in a test
FAQ
Why are arrays not sorted?
In an array the order is part of the data — the second element of a list of steps is not interchangeable with the first. Sorting it would change meaning, so only object keys are reordered.
Does key order matter in JSON?
Not to a parser: the specification calls objects unordered, and no correct consumer should depend on the order. It matters to humans and to text diffs, which is what this tool is for.
How does sorting handle numbers and mixed case?
Keys are compared as strings, so uppercase letters sort before lowercase and 10 sorts before 9. Consistency between two documents is what matters here, and string comparison gives that.