JSON Key Sorter
Sort JSON object keys alphabetically, by length, or in reverse — with recursive nested object support
JSON Key Sorter
Sort JSON object keys alphabetically, by length, or in reverse — with recursive nested object support
Features
- Recursively sort JSON keys alphabetically (or only top-level if recursion is off)
- Toggleable recursive mode
- Pretty-printed output with 2-space indent
- Stats: total keys, depth
- Runs entirely in your browser
How to use
- Paste JSON in the input panel.
- Choose sort order and options.
- Click Sort Keys.
- Copy the sorted result.
Tips & Best Practices
- Sorted JSON gives stable diffs — useful for committing JSON config files where the original order is arbitrary.
- Arrays are left in their original order (JSON arrays are sequences, not sets — order is semantic).
- For deterministic JSON output across languages, JSON Canonical Form (RFC 8785) goes further than alpha-sorting; use a library for that.
- For very large JSON, the parse+stringify round-trip is fine but memory-bound — files >100 MB may stress the browser.
- Mixed-type arrays (objects + primitives) sort the object members internally; the array itself stays in order.
FAQ
Why sort JSON keys?
Sorting keys makes JSON easier to compare, review in PRs, and maintain consistency across config files. It also helps detect duplicate or unexpected fields and produces cleaner diffs when teams edit the same configuration over time.
Does it modify values?
No, only the order of keys changes. All values, arrays, primitive types (strings, numbers, booleans, null), and data types remain untouched and byte-identical to the input.
Does sorting work on nested objects and arrays?
Yes, when the recursive option is enabled, every nested object inside the JSON is sorted at every depth. Array elements keep their original order because order is meaningful in arrays — only the keys inside objects within arrays are reordered.
What sort orders are available?
You can sort keys A-Z (ascending alphabetical), Z-A (descending), or by key length. Length-based sorting is useful when you want to align similar key prefixes visually or group short flag-style keys at the top of an object.
Will sorting break my JSON file?
No, the output is always valid JSON if the input was valid. Indentation is configurable (2 or 4 spaces) and the sorter preserves Unicode strings and escape sequences exactly as they appeared in the source.
Is my JSON sent to a server?
No, sorting runs entirely in your browser using JavaScript. Your JSON — including any secrets, tokens, or proprietary configuration — never leaves your device, which makes the tool safe for production config files.
How does this compare to jq or jsonlint?
jq's --sort-keys flag does the same thing from a terminal, but this tool is browser-based and requires no install. Compared to jsonlint, this sorter focuses specifically on key ordering with options for length-based and reverse sort that most CLI tools do not offer out of the box.