Sort JSON keys alphabetically

Turn on Sort keys and press Format to re-emit every object, at every nesting level, with keys in alphabetical order. Arrays keep their element order. Across a 26-document sample corpus, sorted output differed in all 26 documents while the byte delta was exactly 0. RFC 8259 treats objects as unordered. Sorting runs in this tab.

Input
Output

Formatted JSON will appear here. Press Format, or Cmd / Ctrl + Enter.

Valid JSON7 keys10 lines151 BValidated on this device

Runs in this tab · nothing is uploaded · Verify in 10 seconds →

What this does

Sorting keys re-emits every object in the document (at every nesting level) with its keys in alphabetical order, while arrays keep their element order (reordering an array would change its meaning). The Sort keys toggle below is already on; press Format.

Sorting is free in bytes and almost never a no-op in practice: across the 26-document sample corpus in scripts/fixtures/, sorted output differed from the original in 26 of 26 documents while the total byte delta was exactly 0, same characters, new order. That is the property that makes sorted JSON diff-friendly: two semantically equal documents serialize identically.

When it goes wrong

If the output looks unchanged, check that the Sort keys toggle is actually active (it renders filled, not ghost) and press Format again, sorting is applied at format time, not on toggle. If a downstream consumer breaks after sorting, it was depending on key order, which RFC 8259 says carries no meaning; that consumer is the bug.

When to use this

Sort keys to normalize documents before comparing them: API responses from two environments, config files before committing, exports from different serializers.

This page is a focused view of theJSON Formatter, Validator & Pretty Print, which has the full set of options.

Frequently asked questions

Does key order matter in JSON?

Per RFC 8259, objects are unordered. Parsers must not assign meaning to key order. Sorting is therefore safe for data, but be aware that some non-compliant consumers can behave order-sensitively.

Are nested objects sorted too?

Yes, sorting is recursive: every object at every depth is sorted, including objects inside arrays.

Why sort before diffing?

Two semantically identical documents serialized by different systems often differ only in key order, which floods a diff with noise. Sort both sides, then compare them in the Diff Checker to see only real changes.