About this JSON key sorter
Paste JSON on the left and click A → Z or Z → A. Only object keys are reordered; array order and values stay the same. Use Sort nested objects in the output header when inner objects should follow the same direction.
Sorting runs entirely in your browser. Invalid JSON shows an error under the input; the output pane may keep the last successful sort until you fix the text. After sorting, open the JSON formatter to pretty-print or minify, or use JSON compare on two payloads. For trailing commas or comments, use JSON repair & validate first.
JSON key order — background
Object key order and JSON meaning
In RFC 8259, a JSON object is an unordered set of name/value pairs. Parsers often preserve the order keys appear in the text, but many equality checks treat {"b":1,"a":2} and {"a":2,"b":1} as the same data. Reordering keys changes the serialized text, not the logical value, unless your downstream tool defines otherwise.
Why “alphabetical” uses UTF-16 code units
JavaScript compares key names as strings by UTF-16 code unit value: capital A–Z before lowercase a–z, then digits and other characters. That is not locale collation (so it is not pinyin or dictionary order for non-Latin scripts). The same key list always sorts the same way in engines that follow this rule.
Arrays vs objects: what stays fixed
- JSON arrays are ordered lists: element index meaning does not change when you sort keys elsewhere in the document.
- Sorting object keys only permutes properties within each affected object; numbers, strings, booleans, null, and nested structure content stay the same.
- A root array is still an array after formatting; sorting keys inside objects within that array is a separate option from reordering array elements.
Duplicate key names in one object
JSON syntax allows repeating the same key string in one object, but ECMAScript JSON.parse keeps the last occurrence and drops earlier ones. If your source has duplicate keys, sorting only reorders members in the text—you should still treat the parsed result as “last wins” when validating semantics.
Typical workflows
Stable text for review
Normalize key order before pasting JSON into tickets, chat, or side-by-side review so readers are not distracted by shuffled property names.
Cleaner diffs on config files
When a repo stores JSON configs, a consistent key order reduces noisy git diffs even when the underlying data did not change meaningfully.
Nested objects in large payloads
Turn on nested sorting when deep objects should all follow the same direction; leave it off when only the outer envelope should be normalized.
Frequently asked questions
How do I sort JSON object keys online?
How to alphabetically sort JSON keys?
Does JSON key order matter?
How to sort nested JSON object keys?
Are keys inside JSON arrays sorted?
Should I sort JSON keys before comparing two files?
Is sorted JSON uploaded to a server?
What if my JSON is invalid or has trailing commas?
Does sorting change numbers or 1.0 vs 1?
Quick patterns
{"z":1,"a":2}Outer keys only — default{"z":1,"a":{"b":1,"a":2}}Nested sort off — inner b,a unchangedSort nested onSame JSON — inner keys sort too[{"z":1,"a":2}]Root array — see hint in output