JSON Sorter
Sort JSON keys alphabetically, A to Z or Z to A, in every nested object. Choose case-sensitive, case-insensitive or natural order, and sort lists by value or by a field when you need to.
Sort keys · nested objects · lists by value or field
Valid JSON · object with 5 keys · 3 levels deep · 280 bytes
{
"Version": "2.1.0",
"admins": [
{
"id": 3,
"name": "Sam"
},
{
"id": 1,
"name": "Ava"
}
],
"database": {
"primary": "db-1",
"replica10": "db-10",
"replica2": "db-2"
},
"features": [
"search",
"cart",
"accounts"
],
"server": {
"host": "0.0.0.0",
"port": 8080
}
}14 keys moved in 5 objects. Lists keep their order unless you choose to sort them.
Everything runs in your browser; nothing is uploaded.
Why sort JSON keys?
- Compare two files. Two JSON files with the same data but a different key order look completely different in a diff. Sort both the same way and only the real changes show.
- Cleaner version control. Config and translation files that are always saved sorted give small, readable Git diffs and fewer merge conflicts.
- Find keys faster. In a long object, alphabetical order means you know where to look.
- Stable tests and hashes. Snapshot tests, caches and signatures need the same output every time, whatever order the code built the object in.
Sorting keys never changes the data: the JSON standard treats an object as an unordered set of names and values. List order does matter, so ["first", "second"] is left alone unless you ask to sort it.
How to sort JSON online
- Paste your JSON or open a file. Mistakes such as trailing commas are pointed out, with a one-click fix.
- Pick the order: A → Z or Z → A, and case-sensitive, ignore case or natural.
- Decide about lists. Leave them as they are (the default), sort plain values, or sort lists of objects by a field such as
idorname. - Copy or download the sorted JSON, indented or minified.
The result updates as you change options. Long numbers keep every digit, and number-like keys such as "10" are sorted like any other key.
Sort options explained
| Option | What it does | Example |
|---|---|---|
| A → Z / Z → A | Ascending or descending key order | a, b, c / c, b, a |
| Case-sensitive | Character-code order: uppercase before lowercase, digits first. Same as jq -S and Python | Zebra, apple, banana |
| Ignore case | Dictionary order, like VS Code’s Sort Document | apple, banana, Zebra |
| Natural | Numbers inside keys sort by value | item2, item10 |
| Nested objects | Sorts every object at every level; off sorts the top level only | on by default |
| Sort plain values | Sorts lists of numbers, text, true/false and null | [10, 9, 1] → [1, 9, 10] |
| Sort lists of objects by | Orders objects by one field; items without it go last | by id: 1, 2, 3 |
Numbers in a list are sorted by value, not as text, so 9 comes before 10. Mixed lists go null, then false/true, then numbers, then text.
Example: sort a config file
This config (the example in the tool) was written by hand, in no particular order:
Step 1: A → Z, case-sensitive
Every object is sorted, including the ones inside admins. Two things look odd: Version comes first, because uppercase letters come before lowercase in character order, and replica10 comes before replica2, because 1 comes before 2.
Step 2: Switch to Natural
Now it reads the way a person would sort it: Version sorts under V, after server, and replica2 comes before replica10. The features list kept its order, because list order can matter.
How to sort JSON in code and editors
# Python: sorts nested objects too
json.dumps(data, sort_keys=True, indent=2)
# Command line, with jq
jq -S . config.json > sorted.json
// JavaScript: sort keys at every level
function sortKeys(value) {
if (Array.isArray(value)) return value.map(sortKeys);
if (value && typeof value === "object") {
return Object.fromEntries(
Object.keys(value).sort().map((key) => [key, sortKeys(value[key])])
);
}
return value;
}
// Sort a list of objects by a field
items.sort((a, b) => a.id - b.id); // numbers
items.sort((a, b) => a.name.localeCompare(b.name)); // text
sorted(items, key=lambda item: item["id"]) # PythonIn VS Code, open the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on a Mac) in a JSON file and run JSON: Sort Document. It sorts nested objects too, ignoring case.
Two JavaScript traps:
[10, 9, 1, 100].sort()gives[1, 10, 100, 9], because it compares numbers as text. Pass(a, b) => a - b.- Objects always list integer-like keys first. However you sort
{"b", "10", "2"}, the object comes out"2", "10", "b". The tool above doesn’t have this problem.
Frequently asked questions
Does sorting JSON keys change the data?
No. JSON objects are unordered, so any reader gets the same values whatever the key order. Sorting lists is different: list order can carry meaning (steps, rankings), which is why lists are only sorted when you ask.
Why do uppercase keys come before lowercase ones?
Case-sensitive sorting uses character codes, where A–Z (65–90) come before a–z (97–122). That is what jq -S and Python’s sort_keys do. Choose Ignore case for dictionary order.
How do I sort a JSON array by a value?
Paste the JSON and choose the field under Sort lists of objects by, for example price or name. Numbers sort by value, text alphabetically, and items without that field go to the end.
Why does key10 come before key2?
Alphabetical order compares one character at a time, and 1 comes before 2. Natural order reads the whole number, so key2 comes before key10.
Sources
- RFC 8259, section 4: Objects: objects are unordered collections
- Python docs: json: sort_keys
- jq manual: the --sort-keys / -S option
- MDN: Array.prototype.sort(): why numbers sort as text by default
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.