Lintify Logo
Lintify
Validators & Formatters

JSON Sorter — Sort JSON Keys Alphabetically

Recursively sort every key in your JSON object alphabetically. Useful for normalizing exports, generating deterministic snapshots, and reducing Git diffs.

JSON input
1
Sorted JSON
Output will appear here…

Sort JSON keys at every depth

JSON objects are unordered by definition, but in practice every parser preserves the insertion order of keys. That is convenient most of the time — you can put the most important fields at the top of a response, for example — but it also means the same logical object can produce two different byte sequences depending on which code path produced it. Sorting the keys recursively makes the representation deterministic, which has practical benefits for diffs, caching, and snapshot testing.

Lintify walks your JSON document and sorts every object's keys alphabetically. Arrays are left untouched, because arrays are ordered by definition — [1,2,3] and[3,2,1] are genuinely different documents. Only object keys are sorted. You can choose between case-sensitive and case-insensitive sorting from the toolbar.

Why sorted keys matter for version control

When two developers independently update the same JSON config file, the diff that Git shows depends on key order. If both developers added keys at the end of the file (in the order they happened to think of them), Git will show many lines changed even though only a few keys were actually added. Sorting the keys before committing eliminates this noise — the diff becomes the real diff, not an artifact of insertion order.

The same logic applies to snapshot testing. If your test runner captures a JSON response and compares it to a stored snapshot, key order changes will produce spurious failures. Sorting the keys before snapshotting makes the test robust to insertion order, so it only fails when the actual data has changed.

Sorting and stable hashing

If you hash a JSON document to detect changes — for HTTP ETag headers, cache keys, or change-detection pipelines — you need a stable byte representation. Without sorting, the same logical object can produce different hashes depending on how it was constructed in memory. Sorting the keys first guarantees that two objects with the same keys and values produce the same hash, regardless of insertion order.

Case sensitivity

By default, Lintify sorts case-sensitively, which matches how JavaScript compares strings — uppercase letters sort before lowercase because their character codes are lower. This meansApple comes before apple, which may or may not be what you want. Toggle to case-insensitive sorting from the toolbar if you want Apple andapple to sort adjacent to each other.

Frequently asked questions

Common questions about the Sorter tool.

Why would I sort JSON keys?
Sorting keys makes JSON deterministic — the same logical object always produces the same byte sequence. That helps with version control (smaller, more meaningful diffs), caching (stable hash keys), and snapshot testing (no spurious failures when key order changes).
Does sorting affect array order?
No. Arrays are ordered collections and their elements keep their original positions. Only object keys are sorted. If you need to sort an array, extract it and sort it before putting it back into your JSON.
Is the sort case-sensitive?
By default, yes — uppercase letters sort before lowercase because that is how JavaScript compares strings. If you want a case-insensitive sort, lowercase every key before passing the data in, or use the toggle on the page to switch the comparator.
Can I sort by value instead of by key?
Sorting by key is the natural operation for objects. To sort by value, you usually have an array of objects and want to sort that array by a specific field — flatten your data, sort the array in JavaScript, and then re-paste it. Lintify keeps the tool focused on key sorting to avoid confusion.
Will sorting break my API contract?
Most modern JSON parsers preserve insertion order (including the JavaScript engine in every browser), but the JSON spec does not guarantee it. If your consumer reads keys positionally instead of by name, sorting will break them — but that consumer is already broken and you should fix it before shipping.

Related tools