JSON Key Sorter
Sort JSON object keys alphabetically or in reverse order. Recursively processes nested objects so every level is consistently ordered — great for diffs, readability, and canonical serialization.
Features
🔤 Alphabetical Sorting
- Ascending (A→Z) or descending (Z→A)
- Case-sensitive locale comparison
- Works on any valid JSON object
- Preserves all values unchanged
🌲 Recursive Processing
- Sorts keys at every nesting level
- Objects inside arrays are sorted too
- Optional — disable for top-level only
- Handles deeply nested structures
⚙️ Flexible Options
- Sort primitive arrays optionally
- 2-space indented output
- Copy or download result instantly
- Zero-dependency, runs in browser
JSON Key Sorting Guide
How to Sort JSON Keys
Paste your JSON into the input panel, choose your sort order and options, then click Sort JSON. The sorted output appears on the right ready to copy or download.
// Input
{"zebra": 1, "apple": 2, "mango": 3}
// Output (ascending)
{"apple": 2, "mango": 3, "zebra": 1}
Why sorted JSON makes teams faster
Key order has no meaning in a JSON object, but it matters a great deal to people reading diffs. Sorting keys consistently turns noisy reviews into small, focused changes and makes files easier to scan.
Tips and common pitfalls
- Sort configuration and translation files before committing so reorderings by editors or tools do not show up as changes.
- Sorting keys does not change the data, but sorting arrays does. Only sort arrays when their order carries no meaning, such as a list of tags.
- Sort both documents before comparing them to find real differences quickly, or use our JSON Diff tool.
- For signatures and hashing, sorting alone is not enough; use RFC 8785 canonicalization, which also normalizes numbers and strings.
More questions
Can I enforce sorted JSON in my repository?
Yes. A pre-commit hook or CI step can run a formatter such as Prettier with a sort plugin, or jq -S ., and fail if a file changes.
Does JSON.stringify keep insertion order?
For string keys, yes. Integer-like keys are an exception: JavaScript always lists them first, in ascending numeric order.