JSON Key Sorter

Paste JSON on the left and click A → Z or Z → A to reorder object keys. Sort nested objects is in the output header. Invalid input shows an error under the input; the output may keep the last successful sort.

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

  1. JSON arrays are ordered lists: element index meaning does not change when you sort keys elsewhere in the document.
  2. Sorting object keys only permutes properties within each affected object; numbers, strings, booleans, null, and nested structure content stay the same.
  3. 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?
Paste JSON on the left and click A → Z or Z → A. The output is pretty-printed JSON with reordered keys. Copy from the output or use the copy control. Only object keys move; values stay the same.
How to alphabetically sort JSON keys?
Click A → Z for ascending character order on key names (uppercase before lowercase, UTF-16 rules). Click Z → A for descending. This is not locale-aware collation—it is the same order JSON tooling uses in JavaScript.
Does JSON key order matter?
For JSON.parse, {"b":1,"a":2} and {"a":2,"b":1} are equal. Key order still matters for readable diffs, documentation, and stable file comparisons, which is why teams normalize order before review.
How to sort nested JSON object keys?
Check Sort nested objects in the output header, then click A → Z or Z → A again. Every nested object gets sorted in the same direction. Objects inside arrays stay in array order; nested sort only affects keys inside those objects when the option is on.
Are keys inside JSON arrays sorted?
Array element order never changes. With nested sort enabled, keys inside an object that sits in an array can be sorted, but the array will not reorder its elements.
Should I sort JSON keys before comparing two files?
Many compare tools ignore object key order, but sorting both sides the same way still makes raw text easier to read before you look for value changes.
Is sorted JSON uploaded to a server?
No. Sorting runs on the text you pasted, entirely in your browser; nothing is uploaded.
What if my JSON is invalid or has trailing commas?
This page accepts strict JSON only. You will see an error under the input, often with line and column. Fix syntax on JSON repair & validate, then sort again.
Does sorting change numbers or 1.0 vs 1?
Sorting only moves keys. Pretty-print may display 1.0 as 1 because that is normal JSON number formatting—the numeric value is unchanged.

Quick patterns

  • {"z":1,"a":2}Outer keys only — default
  • {"z":1,"a":{"b":1,"a":2}}Nested sort off — inner b,a unchanged
  • Sort nested onSame JSON — inner keys sort too
  • [{"z":1,"a":2}]Root array — see hint in output