Code Beautify / MULTIVERTO

Sort JSON keys

Alphabetize object keys recursively without changing array order.

Live converterYour input stays in this browser. No text is uploaded for conversion.
The file stays in your browser.
Chain tools

Apply each text tool to the previous result.

01 / Guide

How it works

Parse JSON, sort each object’s member names, and indent the result.

Good to know

Alphabetize object keys recursively without changing array order.

02 / Example

Example

Your input{"z":"Welcome","a":{"z":"Hello","a":true}}
Result{ "a": { "a": true, "z": "Hello" }, "z": "Welcome" }

03 / Guide

Sort JSON keys — How it works

What the conversion does

Alphabetize object keys recursively without changing array order. Parse JSON, sort each object’s member names, and indent the result.

Worked example

Start with the input shown on this page: {"z":"Welcome","a":{"z":"Hello","a":true}}. The tool produces: { "a": { "a": true, "z": "Hello" }, "z": "Welcome" }. Try the example first so you can compare the two representations. Then replace it with your own material. The result is plain text that you can copy into an editor, a test fixture or a request only after checking that its destination expects the same form.

Format rules and limits

This operation parses JSON rather than sorting lines of text. Every object is visited recursively and its member names are placed in JavaScript lexicographic order; array elements stay in their original positions because array order usually has meaning. Values keep their JSON type, including true, false, null and numbers. Indentation changes so the output can be reviewed, but numeric spelling and insignificant whitespace may differ from the source. JSON object key order is often semantically irrelevant to applications, although order can matter to diffs, snapshots and protocols that sign exact bytes. Do not use this output as a canonical JSON signature format. Duplicate member names in the source are resolved by the JSON parser before sorting, so inspect such data in a dedicated parser if retaining every occurrence is essential.

Check the result

Keep the original beside the transformed text while you inspect it. Compare a small known case first, especially one containing punctuation, a non-ASCII character, a repeated value or an empty field relevant to your data. A readable output is not proof that the receiving program accepts the same schema or conventions. If you exchange data between applications, run the receiving parser and review a few records after import. Keep important source files under version control so changes are reversible. Processing takes place in your browser; this page does not send the pasted input to a conversion server. Browser memory and the clipboard still need ordinary care on shared devices.

The source and result have different roles even when they look similar. The method above defines the accepted subset rather than every extension of the named format. For a strict receiving system, try a small known case before changing many records. If validation fails, return to the original input and the first reported error; editing only the generated result can hide the cause.

For JSON key sorting, parse the output again and compare its data with the parsed input, rather than comparing the original bytes. Check that arrays kept their order and that every object was sorted, including objects nested inside arrays. If the result will be signed or hashed, use the exact canonicalization required by that protocol instead of assuming alphabetical keys are sufficient.

How this conversion transforms the input
JSON — Input
Read and transform structure
JSON — Result