Developer Tool

JSON Sorter

Sort JSON object keys alphabetically — recursively or only at the top level — and optionally sort arrays of primitives. Pick A-Z or Z-A, control case sensitivity, and choose your indent style. Everything runs in your browser.

Validation

Paste JSON, choose your options, then click Sort JSON.

Output actions

How it works

  • • Object keys are sorted by string comparison
  • • Arrays of primitives sort by value when enabled
  • • Arrays of objects sort by JSON-stringified element
  • • Original key order is preserved if "Keep original order" is picked
  • • Comments and trailing commas are not valid JSON — strip them first

Sorted JSON

Client-side only — ready to copy or download.

How to use

Paste any valid JSON, pick the sort order, choose whether arrays sort too, and click Sort JSON. Output appears below in your chosen indent style.

Good for

Stable diffs in pull requests, canonical config files, deterministic API responses for snapshot testing, and tidying messy hand-edited JSON.

Privacy

No data ever leaves your browser. Parsing, sorting, and stringifying all happen client-side. Nothing is uploaded or logged.

About the JSON Sorter

The JSON Sorter takes any valid JSON and rewrites it with object keys sorted alphabetically — recursively at every level, or only at the top. It optionally sorts arrays of primitives, lets you pick case-sensitive comparison, and outputs in your chosen indent style. The result is canonical, diff-friendly JSON.

  • Sort keys ascending (A → Z), descending (Z → A), or keep original order
  • Choose recursive sort or top-level only
  • Optional array sorting — by value for primitives, by stringified form for objects
  • Case-sensitive or case-insensitive comparison
  • Four output formats: 2 spaces, 4 spaces, tab, minified
  • Quick stats — total keys, arrays, and maximum depth
  • "Output → Input" button to chain operations
  • Validates JSON before sorting and shows clear parse errors
  • 100% client-side — no uploads, no logging

How to Use the JSON Sorter

  1. 1

    Paste your JSON

    Drop any valid JSON into the Input box — objects, arrays, or any combination. Click Sample data to see a working example.

  2. 2

    Pick a sort direction

    Ascending is the most common — it makes JSON files diff cleanly in version control. Descending reverses that. Keep original order only sorts the things you ask for (e.g. arrays) without touching object keys.

  3. 3

    Decide on arrays

    By default arrays keep their order — important if the JSON represents a queue, a list of steps, or anything order-sensitive. Switch to Sort items if order doesn't matter for your data (e.g. tag lists).

  4. 4

    Choose depth and indent

    All nested levels recursively sorts every object. Top level only sorts just the outer keys. Pick your indent (2/4 spaces, tab, or minified for compact output).

  5. 5

    Click Sort JSON

    The output appears at the bottom and the Stats card shows key/array counts and max depth. Use Copy or Download .json, or use ↻ Output → Input to chain another sort pass.

Tip: Sorting JSON keys before checking into Git produces a canonical form — small content changes show up as small diffs instead of getting buried in re-ordered keys. Run the sorter as a pre-commit hook or formatter step.

Common Use Cases

Cleaner Git Diffs

  • • Sort package.json, tsconfig.json, and other config files
  • • Reduce noise in pull request reviews
  • • Make merge conflicts easier to resolve

Snapshot Testing

  • • Stabilize API response fixtures
  • • Avoid false test failures from reordered keys
  • • Compare snapshots across runs and environments

Canonical Forms

  • • Produce deterministic JSON for signing or hashing
  • • Match output across different programming languages
  • • Build content-addressable storage keys

Easier Inspection

  • • Find keys in large config files faster
  • • Spot duplicate or near-duplicate entries
  • • Review unfamiliar JSON exports

Reproducible Builds

  • • Stabilize build manifests
  • • Ensure consistent dependency lockfile ordering
  • • Make builds bit-for-bit reproducible

Documentation & Examples

  • • Present JSON schemas in alphabetical order
  • • Make API example payloads easier to scan
  • • Tidy hand-written tutorials and blog snippets

Frequently Asked Questions

Does sorting JSON keys change the meaning of the data?

No. The JSON spec says object key order is not significant{"a":1,"b":2} and {"b":2,"a":1} are equivalent. Sorting keys doesn't change semantics, only presentation. Array order, however, is significant — which is why the sorter leaves arrays alone unless you opt in.

Will the sorter modify arrays inside my JSON?

Only if you set Arrays → Sort items A → Z (or Z → A). The default Preserve order leaves arrays exactly as you typed them — useful for queues, steps, ordered lists, and anything order-sensitive.

What's the difference between "All nested levels" and "Top level only"?

All nested levels sorts every object in the tree. Top level only sorts only the outermost object's keys — useful when you want to bring a few configuration fields to the top while keeping nested structures (like database column lists) in their existing order.

How does case-sensitive sorting work?

When Case-sensitive sort is on, uppercase letters sort before lowercase (so Apple < apple < banana). When off, comparison ignores case and groups letters together (Apple and apple sort next to each other).

My JSON has comments and trailing commas — why doesn't it parse?

Strict JSON does not allow comments or trailing commas. Those features are JSON5 / JSONC. Strip them before pasting, or use a tool that converts JSON5 → JSON first.

Does the sort preserve duplicate keys?

No — and this is a JSON property, not a tool limitation. JSON.parse keeps only the last occurrence of each key. If your input has {"a":1,"a":2}, only {"a":2} survives parsing.

Can I sort large JSON files?

Yes — the sorter handles megabyte-sized inputs comfortably in modern browsers. For very large files (tens of megabytes), pasting may slow the UI for a moment, but the sort itself is fast. Everything runs locally with no upload.

How do arrays of objects get sorted?

When you enable array sorting and the array contains objects (not primitives), each element is compared by its JSON-stringified form. This produces a stable, deterministic order — useful for canonicalization, though not always the most semantically meaningful sort. For value-based sorting of object arrays, you'd typically pick one key and sort by it in code.

Is my data sent anywhere?

No. All parsing, sorting, and stringifying happens in your browser using JSON.parse and JSON.stringify. Nothing is uploaded, logged, or stored. Closing the tab discards your data.