JSON Key Sorter
Sort every object's keys alphabetically throughout a JSON document, recursively — makes diffs clean and configs easy to scan.
912 views
How It Works
Paste JSON and every object's keys come back sorted alphabetically. The important part is that this sorting is recursive: the tool doesn't just reorder the top-level object's keys and stop — it walks into every nested object, at every depth, and alphabetises each one independently. Sorting only the outermost level would leave a document's inner structure untouched, which defeats the purpose for anything more complex than a flat object; real-world JSON (API responses, config files) is almost always nested several levels deep.
For example, given {"user":{"zip":"1","name":"A"},"active":true}, the tool doesn't just move active before user at the top — it also reaches inside the user object and swaps name before zip, producing {"active":true,"user":{"name":"A","zip":"1"}}. Arrays are left alone: their element order is preserved exactly, since array order is semantically meaningful (arrays are ordered by definition) while object key order, per the JSON specification, is not.
Good to Know
The main use case is making diffs and version-control comparisons meaningful. Two JSON documents that hold identical data but were serialized with keys in different orders will produce a huge, noisy text diff if compared directly — every line looks different even though nothing actually changed. Running both through this sorter first collapses that noise: with keys in the same alphabetical order, a plain-text diff shows only genuine content changes, not incidental reordering. It's equally useful for hand-editing config files or making an unfamiliar API response easier to scan.
Frequently Asked Questions
Does this change the data, only the order?
Only key order changes — values, nesting and array contents are untouched. JSON objects are unordered by the spec, so this is always a safe, non-breaking transformation.
Does sorting apply to nested objects, or just the top level?
It's fully recursive — every object at every nesting depth gets its own keys alphabetised independently, not just the outermost one. Sorting only the top level would leave inner objects in their original, possibly inconsistent order.
What if my JSON is invalid?
You get a clear parse error instead of silent failure — fix the syntax issue it points to and try again.
Does it sort arrays too?
No — array element order is preserved exactly, since arrays are ordered by definition and reordering them would change meaning. Only object keys are alphabetised.
Why would I sort JSON keys before comparing two files?
Plain-text diff tools compare line by line, so two JSON files with identical data but differently ordered keys look almost entirely different in a diff even though nothing meaningful changed. Sorting both files' keys the same way removes that noise, leaving a diff that reflects only real content changes.
Similar Tools
Report a Problem
JSON Key Sorter
Comments
No comments yet — be the first to write one!