Sort JSON Keys
Normalise JSON by sorting all keys alphabetically at every nesting level. Makes diffs cleaner and output predictable.
FORMAT
INDENT
Tips
Paste JSON in the left pane. Output updates instantly.
How it works
After JSON.parse turns your input into an in-memory tree, the tool walks every object and rebuilds it with keys in alphabetical order, recursing into nested objects and through array elements. Keys that are whole numbers (such as "2" or "10") always come first, in numeric order, because JavaScript objects keep them that way. JSON.stringify then emits the normalised tree with two-space indentation, or four spaces if you pick that option. The stable key order makes diffs between two JSON files line up cleanly so real changes stand out.
Example
Nested objects are sorted too, arrays keep their order, and whole-number keys come first:
{"b":{"d":1,"c":2},"a":[{"z":0,"y":1}],"10":"x","2":"y"}{
"2": "y",
"10": "x",
"a": [
{
"y": 1,
"z": 0
}
],
"b": {
"c": 2,
"d": 1
}
}Processing runs in your browser
All processing happens inside your browser tab. Our servers are not involved at any point.
Technical specification
JSON syntax is defined in RFC 8259 (IETF, 2017) and ECMA-404. The tool parses with the browser's strict JSON.parse, so comments and trailing commas are errors, and writes the result with JSON.stringify.
- Standard
- ECMA-404 / RFC 8259
- Browser API
- Native
JSON.parseandJSON.stringify - Indent
- 2 or 4 spaces (none when minifying)
- Size limit
- Browser memory
Related operations
For converting between data formats, try CSV to JSON or the YAML formatter. To decode tokens, use the JWT decoder. For escaping URL data, try URL encode.
Frequently asked questions
- Why sort JSON keys?
- Sorted keys make it easier to diff two JSON files and to find specific fields quickly.
- Does it sort nested objects too?
- Yes. Keys are sorted recursively through every level of the object.
- Does the order of array items change?
- Array order is preserved; only object keys are sorted.
- Are uppercase and lowercase keys sorted together?
- Sorting uses JavaScript's default string order, which compares UTF-16 code units, so every uppercase ASCII letter (A-Z) comes before every lowercase one (a-z): "Zebra" sorts before "apple". Keys that are whole numbers come first of all, in numeric order.
Last reviewed September 30, 2026
Other pages for this tool
Related tools
- Background reading: Complete guide to data tools
- Step by step: Turn a CSV into clean JSON for an API