JSON sort by key

Processed locally
app.sort.view

You can also load data via #data={"name":"Ada"} or #url=... It is cleared from the address bar after it is read.

Sort object keys by field name so two exports are easier to compare. Many serializers do not guarantee key order; sorting first makes Diff much cleaner. You can also commit the sorted result to Git to reduce noisy key-order churn.

Recursive sort

Keys in nested objects are sorted by name too. Deep configs are handled in one pass—no manual layer-by-layer cleanup.

Keys are sorted lexicographically so output is stable across languages and tools.

Array items are not reordered

List order usually has meaning, so the original order is kept. Timelines, steps, and rankings are not sorted by value.

When you only want to normalize object keys and leave lists alone, this page is clearer than casually checking the option on the formatter.

Use with Diff

Sort first, then compare, to cut noise from “only the key order changed.” Sort both sides before pasting into Diff.

The formatter also has a “Sort keys” option with a similar effect. This page focuses on that one job.

Example

Before sort
{
  "z": 1,
  "a": { "n": 2, "m": 1 },
  "m": 3
}
After sort
{
  "a": {
    "m": 1,
    "n": 2
  },
  "m": 3,
  "z": 1
}
Are string values sorted lexicographically?

Object keys are sorted by name. String values are not sorted.

Is it stable?

The same input should produce the same key order every time, which is Git-friendly.

Does it change array order?

Array items are not reordered. Only object keys are sorted.

How are non-ASCII keys sorted?

JavaScript’s default string comparison is used. Mixed scripts may not match a phonetic sort, so agree on a convention in the team.

Recommended workflow

  1. Paste two JSON documents that are equal in content but have messy key order, and sort each.
  2. Copy the results, then compare them on the Diff page.
  3. For storage or snapshot tests, treat the sorted version as the canonical output.
  4. If a business array has meaningful order, do not switch to a script that shuffles lists.

Sorting only normalizes object keys. It is not general data cleaning. Use the clean page to drop empty values and redact.