JSON Object Formatter
Format a JSON object with its keys in alphabetical order at every level of nesting, two spaces to an indent. The page opens with sorting already on and an example object loaded, so you can see what it does to nested objects before you paste your own. Arrays are left exactly as written, because the order of an array is data and reordering it would change what the document says.
Formatted
Common questions
- How are the keys ordered?
- A to Z, case-insensitively, at every level. Comparing without case means Name and age come out in the order a person expects rather than in code-unit order, where every capital letter sorts before every lowercase one. When two keys are the same apart from case, they keep the order you wrote them in, so a document containing both B and b is not silently rearranged twice.
- Does sorting touch arrays?
- No. Array elements stay in the order you wrote them, because in JSON that order is meaning: the first item of a list is the first item. Objects inside an array are each sorted internally, so a list of records comes out with consistent field order while the records themselves stay in sequence.
- Does sorting change my values?
- No. The sort moves whole members around in the token stream rather than parsing the document into an object and printing it back out. Your number literals are copied character for character, so a 20 digit ID keeps all 20 digits, and strings keep their exact escapes. Nothing is rounded, retyped or re-encoded.
- Why would I want keys sorted?
- Mostly to make two documents comparable. Config files and API responses that differ only in key order produce a diff full of noise, and sorting both sides first reduces it to the changes that matter. It is also a quick way to find a key in a long object, and to spot two keys that are nearly the same name.
- Can I turn it off?
- Yes, with the Keys control under the tool: As written keeps your own order, which is the tool's normal behaviour and what the main JSON formatter opens on. The setting applies to the Copy button and to Minify instead, so a one-line copy has the same key order as the indented one on screen.
- What if the JSON does not parse?
- You get the mistake named, with a line and column, and nothing is sorted: there is no reliable order to impose on a document whose structure is not yet known. Fix the reported line and the sorted output appears. Switch Show to Verdict to put the pass or fail message at the top of the pane.
Exact. Key order, big integers and precision are preserved. Nothing is rounded or reordered behind your back.