Indent:
JSON Input 0 B
Ready
0 chars
Sorted Output 0 B
Sorted JSON will appear here...
0 chars
Features

Why use this sorter

Recursive

Sorting applies to all nested objects, not just the top level. Deeply nested structures get every object's keys sorted consistently.

Ascending or descending

Choose A-Z (default) or Z-A with the "Reverse" option. Useful for prioritizing recent entries or finding the largest keys first.

Deterministic output

Sorted JSON produces the same string every time, enabling safe use as cache keys, ETags, or hash inputs. Perfect for content-addressable systems.

How it works

Conversion explained

1. Parse JSON

Input is parsed into a JavaScript value. Invalid JSON produces a clear error.

2. Walk and sort

The transformer walks the value recursively. For each object, keys are sorted using native Array.sort with optional reverse.

3. Re-serialize

The sorted value is serialized with JSON.stringify using your chosen indentation. Arrays preserve their original order.

FAQ

JSON Sort Keys Tool — frequently asked questions

Does sorting affect arrays?

No — array order is preserved. Only object keys are sorted. If you need to sort array values too, post-process the output or use a custom script. This preserves the semantic meaning of arrays (which are ordered by definition).

Is the sort case-sensitive?

Yes — sorting is case-sensitive using JavaScript's default string comparison. Uppercase letters come before lowercase (e.g., "Apple" before "apple"). For case-insensitive sorting, post-process the output.

Why sort JSON keys?

Three main reasons: (1) cleaner git diffs when keys are added or removed, (2) deterministic serialization for cache keys and hashing, (3) easier visual scanning when looking for a specific key in a large object.

Is sorting reversible?

The data is unchanged — only key order is modified. Sorting again with the same options produces the same output. To restore the original order, you'd need to keep a copy of the unsorted input.