JSON Sort — Sort JSON Keys and Arrays Online

Normalize key order and sort arrays for stable diffs, canonical fixtures, and readable configs. Choose alphabetical, natural, or numeric order. All processing stays in your browser.

Loading…
JSON sort, canonical order playbook
Sort object keys and arrays to produce deterministic, diff-friendly JSON. Control scope, direction, and depth, all locally.

Developer notes

Sorting runs automatically as you type, paste, upload, load a sample, or change options (short debounce on input; option changes debounced ~250 ms). Sorting parses JSON first — fix syntax errors or use JSON repair. Default scope is `both`; choose `objectsOnly` when you only need key canonicalization for git diffs (array options reset to Preserve order). Natural sort orders `item2` before `item10`. Array `byObjectKey` requires a field name; objects missing the field sort last. Mixed-type arrays sort by typeof order, then value — see unit tests for the exact order. `maxDepth` skips sorting at and below the limit for each branch. Options are not saved between sessions (aligned with other JSON tools). For byte reduction after sorting, use JSON minifier.

JSON sort options

Scope
Sort object keys only, array elements only, or both. Default is `both`; use `objectsOnly` for classic key canonicalization (array order unchanged when array mode is Preserve).
Key mode
Alphabetical (lexicographic), natural, or numeric key ordering. Natural puts `item2` before `item10`.
Direction
Sort keys and array elements in ascending (A→Z) or descending order.
Case sensitive keys
When off, `Apple` and `apple` sort together, ignoring case. This applies to keys only, not string values.
Array sort mode
Preserve input order, sort primitives by value, or sort objects by a field name.
Array object key
Field used when sorting arrays of objects. Objects missing the field sort last.
Primitive array sort
Alphabetical, natural, or numeric ordering for primitive array elements.
Max depth
Limit sorting to the top N levels. Nested subtrees at the limit stay untouched.
Indent size
Spaces per indentation level in the formatted output.
Indent style
Spaces or tabs for output formatting.

When teams pick this route

Normalize API snapshots before JSON Diff in CI. Canonicalize OpenAPI/JSON Schema examples for review. Sort user lists by `name` or `id` for display fixtures. Prepare stable golden files for Jest snapshot tests.

Worked examples

Canonical keys for diff

Before

{"z":1,"a":{"y":2,"x":3},"m":[3,1,2]}

After

Top-level keys sorted to `a`, `m`, `z`. Nested object keys are sorted, and array order is preserved with `objectsOnly`.

Sort array of objects by name

Before

{"users":[{"name":"Zoe","id":1},{"name":"Ada","id":2}]}

After

Users reordered to Ada before Zoe with `byObjectKey=name` and natural sort.

Navigate related JSON tools

Browse the JSON tools hub. Compare sorted output in JSON diff and prettify without reordering in the JSON formatter. Validate with the JSON validator or explore structure in the JSON tree viewer.

JSON sort FAQ

Ordering, arrays, and privacy

How is this different from the JSON formatter?

The formatter adds indentation and optional basic key sorting. JSON Sort is dedicated to reordering keys and arrays with full control over mode, direction, depth, and array behavior.

Does sorting change values?

No. Only the order of object keys and array elements changes. Scalar values and nested content stay the same.

Is array order preserved by default?

Array elements keep their input order while Array sort mode is Preserve order (the default). Reorder arrays by switching to By value or By object key, or set scope to Arrays only / Objects and arrays with a non-preserve array mode.

Do I need to click a Sort button?

No. Sorted output updates automatically as you edit JSON or change options (with a short debounce while typing).

Natural vs alphabetical sort?

Natural sort treats embedded numbers correctly, so `item2` sorts before `item10`. Alphabetical uses plain lexicographic order.

When should I use max depth?

Use `maxDepth: 1` to sort only top-level keys and leave nested objects exactly as pasted. This is useful for partial normalization.

Is my JSON uploaded to a server?

No. Parsing, sorting, and formatting run entirely in your browser.

Validate, format, repair, compare and explore JSON in your browser, alongside the JSON minifier and converters.