JSON Sorter
Sort JSON keys recursively
Paste JSON and sort it first for stable output; array strategies and recovery comparisons are available in Advanced mode.
The full guide also includes pitfalls, worked examples, snippets, FAQs, and related tools for checking results or troubleshooting.
About this tool
Recursively order JSON object keys using the browser’s localeCompare, then format the result with two-space indentation. Arrays keep their order by default; optional scalar-array sorting uses text comparisons, with separate protection for the root array. JavaScript integer-key enumeration and number handling still apply. This is a review aid, not canonical JSON for signing. Drafts are stored locally.
Production Snippets
Scalar-array sorting compares text, not numbers
text
Input:
{"z":[2,10,1],"a":true}
Default output, compacted:
{"a":true,"z":[2,10,1]}
Sort scalar arrays on, ascending:
{"a":true,"z":[1,10,2]}
Keep root array order does not protect the nested z array.Failure Clinic (Common Pitfalls)
Sorted output is used as canonical signing input
Cause: The comparator is localeCompare on text; integer-index keys follow JavaScript enumeration, and numbers are reserialized by JSON.stringify. This is not a canonical JSON algorithm.
Fix: Use it for local review and fixtures under known settings. Cryptographic signatures need the exact canonicalization algorithm required by their protocol.
Frequently Asked Questions
Are arrays always kept in order?
By default, yes. Sort scalar arrays can reorder arrays containing only null, strings, numbers, or booleans. Keep root array order protects only the root array; nested scalar arrays can still be sorted. Arrays containing objects or arrays keep their item order.
Is sorting numeric or canonical?
Keys and scalar-array values use localeCompare on their text forms, with ascending or descending order. Numbers in arrays are not sorted numerically, and JavaScript serializes integer-index object keys in numeric order. This is not canonical JSON for signatures or a cross-locale ordering guarantee.
Does it change anything besides ordering?
JSON is parsed and reserialized with two-space indentation. Number formatting and precision follow JavaScript JSON handling. Invalid JSON is reported on Sort. Input and sorting options are saved in this browser’s local storage.
Keep browsing