JSON Sort Keys
Sort object keys alphabetically.
About this tool
Paste JSON and get it back with every object's keys sorted alphabetically, including nested objects and objects inside arrays. Array order is not changed. Sorted JSON makes diffs and merges much calmer.
How to use
How it works
The tool parses the JSON, rebuilds each object with its keys in default JavaScript sort order (by UTF-16 code unit, so uppercase letters sort before lowercase), and prints with two-space indentation. Arrays keep their order, but objects inside them are sorted.
Worked example
Nested objects and an array
- Input
- {"b":1,"a":{"z":1,"c":[{"y":1,"x":2}]}}
- Output
- { "a": { "c": [ { "x": 2, "y": 1 } ], "z": 1 }, "b": 1 }
- Walkthrough
- a now precedes b, c precedes z inside a, and x precedes y inside the array item.
Limitations
- Sorting is by code unit, not by locale, so Z comes before a and 10 comes before 2.
- Duplicate keys in the input collapse to the last value, as in any JSON parser.
Questions
How do I sort JSON keys alphabetically?
Does it sort arrays too?
Is the sort case sensitive?
Why sort keys before a diff?
Features
- Recursive key sort
- Arrays keep order
- Pretty-printed
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
TypeScript in 100 Seconds
Fireship
Typed JSON payloads show up constantly next to format/validate tools.
Watch on YouTubeHow base64 encoding works
Andrew Schmelyun
Mental model for Base64 encode/decode tools.
Watch on YouTube
- Regular expressions
MDN
JS regex guide aligned with browser-based testers.
- RFC 8259 — The JavaScript Object Notation
IETF
The standards text behind modern JSON interoperability rules.