Why key order matters
JSON objects are semantically unordered, but many diffs, golden fixtures, and cache keys still compare text. Sorting keys makes two equivalent objects compare equal as text without flattening the tree or changing values.
Paste JSON on the left. Object keys are rewritten in UTF-16 order; arrays stay in their original sequence unless you opt in.
An object with mixed-case keys, a number list, and a list of items
Key reordering happens in this tab. Pasted JSON and local .json files are read on your device; this sorter does not post them to our servers.
Reorder every object's keys in the browser, keep arrays as they are unless you opt in, then copy or download the result. This is a key sorter, not a formatter and not a flattener.
Drop in an object, an array, or a mix of both. The sorter walks the tree and rewrites each object's keys. Need a readable tree first? Open JSON Viewer. To change values after sorting, use JSON Editor.
{
"zebra": 1,
"apple": {
"zeta": true,
"beta": [3, 1, 2],
"Alpha": "keep-case"
},
"items": [
{ "name": "Mina", "qty": 2 },
{ "name": "Alex", "qty": 1 }
]
}Keys are compared as UTF-16 code units (case-sensitive, not a locale collation). In the sample, apple rises above items and zebra; inside apple, Alpha precedes beta and zeta because uppercase Latin letters come first. The beta list stays [3, 1, 2] and the items list stays Mina then Alex, unless you enable an optional array sort.
{
"apple": {
"Alpha": "keep-case",
"beta": [
3,
1,
2
],
"zeta": true
},
"items": [
{
"name": "Mina",
"qty": 2
},
{
"name": "Alex",
"qty": 1
}
],
"zebra": 1
}Turn on “sort scalar arrays” to order a list of numbers, strings, booleans, or nulls. To sort an array of objects, type the field name (for example name). Then copy the JSON or download a .json file. For indent-only pretty printing, use JSON Beautifier or JSON Formatter. To collapse nesting into dotted paths, use JSON Flattener.
The goal is a stable, inspectable key order — not a pretty-print and not a flattened map.
| Part of the document | Rule in this tool |
|---|---|
| Object keys | Rewritten in UTF-16 code-unit order, recursively, at every nesting level |
| Case | Case-sensitive: "Apple" precedes "apple", which precedes "banana" |
| Unicode | "Ä" is not folded to "A"; letters sort by their code units, not by language rules |
| Arrays (default) | Left in their original sequence, because JSON arrays are ordered |
| Optional sorts | Pure scalar lists, or object lists by a field you name; missing fields sort last |
JSON objects are semantically unordered, but many diffs, golden fixtures, and cache keys still compare text. Sorting keys makes two equivalent objects compare equal as text without flattening the tree or changing values.
Null sorts first, then booleans (false before true), then numbers in numeric order, then strings in the same UTF-16 order used for keys. A mixed list (a number beside an object) is never auto-sorted, because there is no single obvious order.
These choices are fixed in the current sorter so results stay predictable across browsers.
The comparison is raw UTF-16 code units. It does not follow English, German, or Swedish dictionary order, and it does not honor Unicode collation (so “ä” is not grouped with “a”). If you need language-specific ordering, sort in your own program after export.
Numbers, booleans, and null stay as parsed. The output is pretty-printed with a two-space indent only so the new key order is visible. Invalid JSON is rejected with the parser's message; this page does not attempt a repair.
When you name a field, only that field on each object is compared. Nested paths such as address.city are not walked. Objects that lack the field go to the end, in their original relative order versus other missing-field items.
Use this page when the job is deterministic key order. Indentation, validation, and flattening live elsewhere.
JSON Beautifier and JSON Formatter indent and check syntax while leaving the original key sequence intact.
JSON Flattener turns nested objects into dotted keys and can unflatten them later. That is a shape change, not a sort.
JSON Viewer is for exploring the tree. JSON Editor is for changing values once the keys are in a stable order.
Questions about alphabetical key order, case and Unicode rules, optional array sorts, and how this differs from a beautifier
Edit, format, and beautify JSON
Validate, fix, and inspect JSON
Compare, measure, and map JSON
Convert JSON to other formats
Convert other formats to JSON
Convert, format, fix, and minify XML
Generate code and format other languages