Sort JSON object keys for a more consistent review
The key sorter alphabetizes members of every JSON object, including nested objects. It gives collaborators a consistent property order for review.
When should you use it?
- Normalize fixtures before a text comparison.
- Make a large object easier to scan alphabetically.
- Reduce noisy ordering differences in generated data.
Example: alphabetize nested properties
Object members change order at both levels; numbers and array positions do not.
{"z":1,"a":{"y":2,"b":3}}{"a":{"b":3,"y":2},"z":1}Sort names without reordering the records
Object member order can create noisy text diffs even when the values are unchanged. Recursive key sorting puts names in a consistent order at each object level. Arrays keep their existing order because their positions can carry meaning. The source number tokens are preserved rather than parsed into ordinary JavaScript numbers and written back.
Stable layout is different from canonical serialization
Sorting is useful before reviewing two configuration files, but it does not define a cryptographic canonicalization scheme. Such schemes can also specify number spelling, Unicode handling, and other serialization rules. Use the exact canonicalization required by a signing protocol when generating a signature. Resolve duplicate property names separately, because sorting cannot remove the ambiguity they create for different consumers.
How do I alphabetize JSON object keys without sorting arrays?
Run the key sorter on a valid document. It sorts members at every object level while leaving array positions in place. This is useful when generated objects arrive in different property orders and you want a stable text review.
Nested JSON before and after sorting
textBefore: {"z":1,"a":{"y":2,"b":3}}
After: {"a":{"b":3,"y":2},"z":1}The nested object is sorted too. Values and array item order are not alphabetized.
Is sorted JSON a cryptographic canonical form?
No. This tool changes member order for readability but does not implement a canonicalization standard for signing or hashing. Use the exact format required by your protocol.
What should you check before using the result?
Object order may matter to a consumer that treats JSON as text, even though the data model does not assign it meaning. This tool does not sort arrays or deduplicate keys.
Understand JSON syntaxTechnical reference: JSON syntax and interoperability · RFC 8259