LocalFirstTools.com — data tools that never leave your device
No upload — everything runs on your device

Sort JSON keys alphabetically

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.

Input
Output

Formatted JSON will appear here.

Valid JSON10 lines151 BValidated locally

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, 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 Text Diff tool to see only real changes.