Cryonel

JSON Sort Keys

Recursively sort every object's keys alphabetically, at every depth. Useful before committing generated JSON so diffs only show real changes, not key reordering.

How to use it

Paste JSON and click Sort Keys for a pretty-printed, alphabetically-sorted version, or Sort + Minify for a single-line output. Array order is left untouched — only object keys are sorted.

Why sort JSON object keys?

JSON objects are normally consumed by property name rather than display order, yet a stable order is valuable for people and version control. Two payloads with the same members can look substantially different when serializers emit keys in different sequences. Recursively sorting object keys reduces that noise, makes examples easier to scan, and keeps generated fixtures or documentation consistent. Arrays retain their original order because array position is part of the data and sorting elements could change meaning.

Pretty output versus minified output

Sort Keys produces indented JSON suited to review, debugging, and documentation. Sort + Minify applies the same recursive key ordering but removes insignificant whitespace. Minifying reduces text size, not the size of decoded data, and it is not compression. Both modes parse the input before writing the result, so invalid syntax is rejected with a location-focused error instead of returning a partially modified document.

Example and recursive behavior

Given {"z":1,"profile":{"last":"Lovelace","first":"Ada"},"items":[{"b":2,"a":1}]}, the top-level keys and the keys inside profile are sorted. The items array stays in place, while object keys inside each array element are also sorted. Values are not converted: strings remain strings, numbers remain numbers, and null or boolean values keep their JSON types.

This is not cryptographic canonical JSON

Do not use this convenience formatter as the canonicalization step for signatures, hashes, cache keys, or security decisions. Cryptographic canonicalization specifications define more than alphabetic key order, including exact number serialization, Unicode handling, escaping, and property ordering rules. JavaScript also gives integer-like property names special enumeration behavior, so keys such as "2" and "10" may not display like ordinary text keys. Use the canonicalization algorithm required by the protocol you are implementing.

Duplicate keys and semantic checks

Although some parsers accept duplicate object keys, their meaning is ambiguous. Browser JSON parsing keeps only the last value, so sorting cannot preserve or diagnose every duplicate occurrence. Reject duplicates earlier when the producer must be strict. Stable formatting also does not prove that two documents have the same business meaning: APIs may treat missing and null differently, and arrays may represent sets in one contract but ordered sequences in another.

A practical review workflow

Validate or repair the input, sort both documents with the same mode, then inspect them with JSON Diff. This removes key-order noise while leaving real value and array-order changes visible. Use JSON Flatten when a path-oriented representation is more helpful, or JSON Tree Viewer when you only need to navigate the original structure. Everything entered here stays in the current browser tab and is never sent to a formatting service.

Frequently Asked Questions

Does this change array order?

No — arrays keep their original element order. Only the keys within objects are sorted; sorting array *contents* is a different, order-dependent operation this tool doesn't do.

Does sorting change JSON values?

No. It changes object-key presentation and whitespace only; strings, numbers, booleans, nulls, and array positions keep their parsed values.

Is this canonical JSON for signing?

No. Signature protocols require their specified canonicalization algorithm, including exact number, Unicode, escaping, and ordering rules.

Related Tools