JSON Sorter
Sort JSON object keys recursively — ascending or descending, on this device.
Array values stay in place by default. “Sort values” orders arrays of primitives only — arrays holding objects or arrays are left as they are. Sorting reorders keys and re-indents. Values, types, big numbers and text inside strings ride through byte-for-byte.
Press ? for shortcuts
Do it offline:$ jq -S . file.json
How to use it
- Paste JSON, or drop a .json or .txt file up to 50 MB — small documents reorder as you type; past 2 MB a button runs the sort on press.
- Choose ascending or descending, decide whether case matters, pick an indent, and optionally switch on sorting for primitive-only arrays.
- The status line shows whether the output differs from what you pasted or the document was already sorted, next to the output size in bytes.
- Copy the result, download it as a .json file, or Share a link that reopens the tool with the same input and options.
Paste a JSON document and its object keys come back sorted alphabetically, at every level of nesting, so two files that differ only in key order line up for a clean diff or a stable checksum. Only the ordering moves: values, types, number spellings and the text inside strings are copied through exactly, arrays keep their original sequence, and the sort runs here in your browser.
Examples
{"host":"db-1","port":5432,"pool":{"min":2,"max":20}}{
"host": "db-1",
"pool": {
"max": 20,
"min": 2
},
"port": 5432
}The top keys settle to host, pool, port, and inside pool the pair flips to max, min — the values are untouched.
{"Beta":1,"alpha":2,"Gamma":3}{
"Gamma": 3,
"Beta": 1,
"alpha": 2
}Descending with case folded off drops the names into one Z-to-A run — Gamma, Beta, alpha — not the capitals sorting ahead of the lowercase name.
{"z":[3,1,2],"id":1541815603606036481,"a":"café"}{
"a": "café",
"id": 1541815603606036481,
"z": [
3,
1,
2
]
}Keys reorder to a, id, z while the array [3, 1, 2] holds its place; the nineteen-digit id keeps every digit and café passes straight through.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Repeated keys are kept, not merged
Repeated names are kept, never merged: hand {"b":1,"a":1,"b":2} to the tool and the keys return as a, b, b, not one collapsed b. Which duplicate a reader should trust is a parser question, covered on the JSON Validator page.
Arrays stay put unless you ask
Position often carries meaning, so array order is left alone by default. Turn array sorting on and lists of primitive values are reordered — numbers by magnitude, strings by the key case rule — while an array holding an object or nested array is skipped, with a note saying so.
Only the order changes, never a value's bytes
A big integer such as 1541815603606036481 keeps all nineteen digits, an exponent typed 1E+2 keeps its spelling, an escape typed \u00e9 stays \u00e9 not é, and three spaces inside a string stay three spaces. Only key order and inter-token whitespace change, so a value that was itself signed or hashed rides through unchanged.
How capital letters are ordered
By default keys sort by UTF-16 code unit, which puts every capital ahead of every lowercase letter — so "Z" lands before "a". Case-insensitive ordering folds the two together, and a name differing only in case is placed capital-first: a fixed tiebreak, identical on every run.
Roots without keys, and keys with escapes
When the top level is an array or a single value there are no keys to sort there: a bare number or string returns untouched, and objects nested inside still sort. Keys are rebuilt from their source text, so a key written "café" returns as café and an escaped one keeps its escape.
Common errors
Unexpected '}' at line 1, column 14 — probable cause: trailing comma after the last property.- The comma after the final property promises another name, then the object closes instead. Drop that last comma — JSON, unlike a JavaScript literal, allows none — and the keys sort.
Unexpected "'" at line 1, column 6 — probable cause: single-quoted strings are JSON5, not JSON; use double quotes.- A string is marked by double quotes in JSON; the single quotes here are valid JSON5 but outside the strict grammar. Swap them for double quotes and the sort runs.
Unexpected 'n' at line 1, column 2 — probable cause: property names must be double-quoted.- A bare word where a property name belongs is fine in JavaScript source but rejected here. Quote every key so the parser can read the names it must order.
Unexpected end of input at line 1, column 9 — probable cause: the document is incomplete or truncated.- The text stops partway through a value — usually a clipped paste or an interrupted download. Restore the missing tail first, because half a document has no complete set of keys to sort.
This tool sorts up to 50MB; beyond that, try the CLI: jq -S . file.json- Past 50 MB the page hands the job to the command line rather than sort a partial paste. The jq flag -S sorts keys recursively on your own machine, so nothing is uploaded there either.
FAQ
Does sorting change my data?
No — only the order of object keys moves, along with the insignificant whitespace between tokens. Values, types, numbers and the text inside strings are reproduced exactly, and every example here is regenerated by running the engine at build time.
Ascending or descending — and how is case handled?
Keys sort A to Z by default; descending gives Z to A. Case-sensitive ordering compares raw code units, so capitals come first, while case-insensitive ordering treats "Name" and "name" as neighbours and resolves ties the same way every run.
Are array items reordered too?
Only if you opt in. Arrays keep their given order by default, since position is often meaningful; enabling array sorting reorders lists of primitive values only, leaving any array that holds an object or array in place.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Sort the current input now — required past 2 MB, and a manual re-run in any band.
- ⌘/Ctrl + S
- Save the sorted output as a .json file, overriding the browser's save-page shortcut while focused.
- ⌘/Ctrl + C
- With the tool focused and nothing selected, copy the whole output; select text and only that copies.
- ⌘/Ctrl + Shift + C
- Copy the whole sorted result even when part of the pane is selected.
- t
- Toggle the colour theme, unless you are typing in a field or mid-composition.
- ? or ⌘/Ctrl + /
- Open the shortcuts dialog, where any browser-shortcut conflicts are noted.
- Esc
- Close the top dialog; it never clears the input you pasted.