JSON Key Sorter
JSON Key Sorter parses the value, recursively sorts object entries by key using localeCompare, applies the same process inside arrays, and prints two-space JSON. Array element order is retained. The collation can vary by runtime locale, and parsing/serialization can affect unsafe integers, duplicate keys, lexical escapes, and original ordering. Sorting object keys does not produce a formal canonical JSON signature format.
Runs locally — files stay on your deviceAre array items sorted?
No. Their order is preserved, though objects inside them have sorted keys.
Readable key order is not cryptographic canonicalization
Canonical formats define exact Unicode, number, escape, and ordering rules. This page uses ordinary JavaScript parsing and locale-aware key comparison.
How it works
Objects become sorted Object.entries mappings recursively; arrays map each item without reordering; output uses two spaces.
Key concepts
Object keys only
Arrays remain in source sequence.
Locale-aware comparison
Character ordering is not a raw byte sort.
When to use it
- Make object layouts easier to compare visually.
- Normalize configuration key order for review.
- Sort nested object keys in a test fixture.
When not to use it
- Do not sign this output as a standards-defined canonical form.
- Do not sort arrays whose sequence is meaningful.
- Do not expect stable collation across every locale/runtime.
Worked examples
Object
- Input
{"z":1,"a":2}- Expected output
{"a":2,"z":1}
Keys reorder.
Array
- Input
[3,1,2]- Expected output
[3,1,2]
Items retain order.
Nested
- Input
{"x":{"b":1,"a":2}}- Expected output
Nested keys sorted
Recursion applies.
Common mistakes
Calling it canonical JSON
Formal rules are absent. Correction: Use the specified canonicalization standard.
Expecting array sort
Arrays are only traversed. Correction: Sort arrays with domain rules.
Ignoring locale
localeCompare can vary. Correction: Use an explicit deterministic comparator when required.
Best practices
- Use for human review.
- Preserve arrays unless domain semantics permit sorting.
- Choose a formal canonical scheme for hashes/signatures.
Related operations and differences
CSV to JSON
Choose CSV to JSON when you need to convert a header-based CSV table to JSON.; use JSON Key Sorter specifically for json sort.
Extract JSON Values
Choose Extract JSON Values when you need to list every primitive value in a JSON document.; use JSON Key Sorter specifically for json sort.
JSON Beautifier
Choose JSON Beautifier when you need to format JSON with readable indentation.; use JSON Key Sorter specifically for json sort.
JSON Flattener
Choose JSON Flattener when you need to flatten nested objects into dot paths.; use JSON Key Sorter specifically for json sort.
JSON Minifier
Choose JSON Minifier when you need to remove unnecessary JSON whitespace.; use JSON Key Sorter specifically for json sort.
JSON String Escape
Choose JSON String Escape when you need to escape text for a JSON string value.; use JSON Key Sorter specifically for json sort.
Limitations and privacy
- No selectable collation, formal canonicalization, array sorting, source-order report, lossless number mode, comments, schema, or streaming.
Input is processed locally in this browser and is not uploaded by the tool.
Frequently asked questions
Are nested keys sorted?
Yes.
Are arrays sorted?
No.
Is output cryptographically canonical?
No.
Is indentation fixed?
Yes, at two spaces.