Sort JSON Keys Alphabetically
Recursively sort the keys of a JSON object A→Z or Z→A in your browser, with array order left untouched. Your JSON stays local.
Sort JSON Keys runs entirely in your browser. The JSON you paste is parsed and re-serialized on your device, and nothing is uploaded to ArrayKit.
Open the JSON Formatter
About Sort JSON Keys
Sort JSON Keys reorders the keys of every object in a JSON document into alphabetical order, top to bottom and all the way down into nested objects. Arrays keep their element order — only object keys move — so the data is identical, just canonically ordered. Choose A→Z or Z→A, turn on case-insensitive compare so Name and name group together, and set the indent to 2 spaces, 4 spaces, or a tab. Sorted keys make two config files or API payloads diff cleanly, help you spot a missing field, and give you a stable canonical form for snapshots and cache keys. It is built for developers wrangling settings files, fixtures, and API responses. Everything runs in your browser, so the JSON you paste never leaves your device.
Features
- Recursively sorts keys in nested objects, not just the top level
- Preserves array element order — only object keys are reordered
- Toggle ascending A→Z or descending Z→A key order
- Case-insensitive compare so uppercase and lowercase keys group together
- Choose 2-space, 4-space, or tab indentation for the output
- Copy the sorted JSON or download it as a .json file
- Clear inline error message when the input is not valid JSON
- Runs entirely in your browser — the JSON you paste is never uploaded
How to use the Sort JSON Keys
- Paste your JSON into the input box
- Pick A→Z or Z→A and set the indent width
- Turn on case-insensitive compare if you want mixed-case keys grouped
- Copy the sorted JSON or download it as a .json file
Example
Input
{ "name": "Ada", "id": 42, "roles": ["author", "admin"] }
Output
{
"id": 42,
"name": "Ada",
"roles": [
"author",
"admin"
]
}
Keys are alphabetized while the roles array keeps its original order.
Common errors & troubleshooting
- The output kept the same key order I pasted. — The document may be a JSON array at the top level — arrays are not reordered. Only the keys inside objects are sorted, so a bare array is returned unchanged.
- Uppercase keys all sorted before lowercase ones. — That is the default case-sensitive order (capital letters sort first). Turn on case-insensitive compare to group keys like Name and name together.
- The tool reports invalid JSON on a config file. — Strip trailing commas, comments, and single quotes — those are JSON5 features that standard JSON rejects. Fix the flagged position and paste valid JSON.
- My array of objects still shows the elements in the original order. — That is intended: array order carries meaning, so it is preserved. Each object inside the array does get its own keys sorted.
Frequently asked questions
- Does sorting JSON keys change the data?
- No. Sorting only reorders the keys inside objects; every key, value, and array element is preserved. The result parses to the same data — it is just written in a canonical, alphabetical order.
- Are the keys of nested objects sorted too?
- Yes. Sort JSON Keys walks the whole document recursively, so keys in nested objects and in objects inside arrays are all alphabetized, not just the top-level keys.
- Does sorting keys reorder the items in an array?
- No. Array order often carries meaning, so array elements keep their original positions. Only object keys are reordered; each object inside an array still gets its own keys sorted.
- How does case-insensitive key sorting work here?
- With case-insensitive compare on, keys are ordered ignoring letter case, so Name and name sit next to each other. With it off, uppercase keys sort before lowercase ones, which is the default JSON string order.
- Why would I want to alphabetize JSON keys?
- A canonical key order makes two JSON files diff cleanly, exposes missing or duplicate fields, and gives stable snapshots and cache keys. It also makes large config files far easier to scan by eye.
- Is my JSON uploaded when I sort the keys?
- No. Sort JSON Keys runs entirely in your browser. The JSON you paste is parsed, sorted, and re-serialized on your device, and nothing is sent to ArrayKit.
Related tools
- JSON Formatter — Beautify, minify and validate JSON with error locations.
- JSON Diff — Compare two JSON documents and see a structural, key-order-independent diff.
- JSON Flatten / Unflatten — Flatten nested JSON to dot-notation keys, or unflatten it back.
- JSON Viewer — Text + collapsible tree viewer with expand/collapse and node paths.
- NDJSON to JSON — Convert NDJSON / JSON Lines to a JSON array and back, line by line.
- JSON Escape / Unescape — Escape text into a JSON string or unescape a JSON string back to raw text.
All ArrayKit tools