Transform · Sort JSON

Sort JSON Keys Alphabetically

Reorder every object’s keys alphabetically, at every level, for stable diffs and a canonical shape. Runs in your browser.

No sign-up to start · Runs in your browser

Sort JSON
Open in full editor
Input
Sorted JSON

Runs entirely in your browser — nothing is uploaded.

{"name":"Ada","id":1,"active":true,"address":{"zip":"EC1A","city":"London"}}
To sort JSON keys, paste your JSON below: every object’s keys are reordered alphabetically at every level of nesting, while all values, and the order of array elements, stay exactly as they were. The result is a canonical shape of the same data — the same keys and values, in a predictable order. That makes version-control diffs small and readable, lets you compare two payloads line by line, and gives you a stable key to hash or cache. Sorting runs entirely in your browser.

Sort JSON keys: before and after

Input JSON (unordered keys)
{
  "name": "Ada",
  "id": 1,
  "active": true,
  "roles": ["admin", "editor"],
  "address": { "zip": "EC1A", "city": "London" }
}
Sorted output
{
  "active": true,
  "address": {
    "city": "London",
    "zip": "EC1A"
  },
  "id": 1,
  "name": "Ada",
  "roles": [
    "admin",
    "editor"
  ]
}

Top-level keys become active, address, id, name, roles, and the nested address object is reordered to city then zip. The roles array keeps its original order (admin before editor) because array element order carries meaning and is never touched.

How to sort JSON keys

  1. 1

    Paste your JSON

    Drop your JSON into the input box — or start from the example that is already loaded.

  2. 2

    Sort every key

    Each object’s keys are sorted alphabetically and recursively, so nested objects are reordered too. Arrays and values are left untouched.

  3. 3

    Read the canonical output

    The sorted JSON is re-serialized with clean two-space indentation, ready to copy or diff against a previous version.

  4. 4

    Copy the result

    Copy the canonical JSON straight to your clipboard to paste into a file, a commit, or a comparison tool.

  5. 5

    Open it in the full editor

    Send the sorted JSON to the editor to format or minify it, validate it, explore it as a tree or mind map, and ask the AI copilot about it.

Why sort JSON keys

Runs in your browser

Sorting is 100% client-side. Your JSON never leaves your device — nothing is uploaded and no account is required.

Recursive by default

Keys are sorted at every level of nesting, including objects inside arrays, not just the top-level object.

Values and arrays preserved

Only the order of object keys changes. Every value — and the order of every array element — is left exactly as it was.

Stable, minimal diffs

A canonical key order means the same data always serializes the same way, so git diffs show real changes instead of reshuffled keys.

Easy payload comparison

Sort two responses the same way and they line up field by field, so you can spot the one value that actually differs.

Always valid JSON out

The tool parses your input first and re-serializes it, so a successful sort is also a quick confirmation that the JSON is well-formed.

Why canonical key order matters

JSON objects are unordered by definition, but the text you commit to a repository is not. If one service writes {"id":1,"name":"Ada"} and another writes {"name":"Ada","id":1}, the data is identical yet the two files differ on every line. Sorting keys into a single canonical order removes that noise: the same data always serializes to the same bytes, so a git diff highlights the fields that genuinely changed instead of a reshuffle.

Canonical order also makes comparing payloads practical. When you capture an API response before and after a change, sorting both sides means a line-by-line or text diff lines up field for field, and the one value that moved stands out immediately. Without sorting, a reordered key can make two equivalent responses look completely different.

The same property helps with caching and content hashing. A cache key or ETag derived from a JSON string is only stable if the serialization is stable. Sorting keys before you hash gives you a deterministic string, so logically equal objects produce the same key and you avoid duplicate cache entries for the same data. Snapshot tests benefit for the same reason — a sorted snapshot only churns when the data really changes.

What sorting preserves — and what it does not

Sorting touches one thing only: the order of keys within each object. Every value is preserved exactly — numbers stay numbers, strings stay strings, booleans and null are unchanged, and nested structures keep their contents. Because keys inside objects carry no meaning through their position, reordering them never changes what the JSON represents.

Array element order, by contrast, is meaningful and is always left alone. In the example above the roles array stays ["admin", "editor"] in its original order; the tool never sorts array items, so a list written as ["editor", "admin"] would come back unchanged rather than alphabetized. Objects nested inside arrays do have their own keys sorted, so an array of records is normalized field by field while the records themselves stay in sequence.

Keys are compared with a locale-aware alphabetical comparison, so casing is grouped naturally (alpha, Beta, gamma, Zeta) rather than by raw byte value. It is not a numeric or natural sort: a key like "item10" sorts before "item2" because the comparison is character by character. If your input is not valid JSON, the tool reports an error instead of guessing, so a clean sort doubles as a quick validity check.

Sorting vs. formatting vs. minifying

These three operations are easy to confuse because they all rewrite JSON text, but they change different things. Formatting (pretty-printing) adjusts whitespace — indentation and line breaks — to make the structure readable, without moving any keys. Minifying does the opposite, stripping all optional whitespace to produce the smallest possible single-line payload. Neither one reorders keys.

Sorting is the orthogonal operation: it changes the order of object keys and leaves the meaning identical. It happens to emit pretty-printed, two-space-indented output here, but the defining action is the reordering, not the whitespace. You can think of it as normalizing the shape of the data rather than its layout.

Because they are independent, the operations compose. A common recipe is to sort for a canonical key order and then minify for transport, which gives you a compact string that is also deterministic — ideal for hashing or a cache key. For a file you will read and diff, sort and then format instead. The order of sort versus format or minify does not affect the data, only the final text.

Workflow tips

Sort as the last step before you commit generated or exported JSON — config files, fixtures, seed data, lockfile-style manifests — so that regenerating the file only produces a diff when the underlying data actually changed. Applying the same sort on both sides of a comparison is what makes the technique pay off; a canonical order is only useful when it is applied consistently.

When you are debugging a mismatch between two systems, sort both payloads first, then diff. Reordered keys are the most common reason two equivalent responses look different, and removing that variable usually points straight at the real discrepancy. For content hashing or ETags, run the sort before serializing to your hash input so the digest is stable across runs.

Once the keys are in a canonical order, open the result in the full editor to go further. There you can format or minify it, validate it against a schema, walk it as an interactive tree or a mind map to understand nesting at a glance, and ask the AI copilot to explain a field, generate a type, or transform the structure. Sorting gives you a clean, predictable starting point for all of that.

Frequently asked questions

Is sorting JSON free and private?

Yes. Sorting runs entirely in your browser with no account and no upload — your JSON never leaves your device.

How does the tool decide the key order?

It walks the whole structure and sorts each object’s keys with a locale-aware alphabetical comparison, recursively, so nested objects and objects inside arrays are sorted too. Casing is grouped naturally (for example alpha, Beta, gamma, Zeta) rather than by raw byte value.

Does sorting change my values or my array order?

No. Every value is kept exactly as-is, and elements inside arrays hold their original position because their sequence can be significant. The one thing that moves is where each key sits within its object.

What is the difference between sorting and formatting or minifying?

Formatting and minifying only change whitespace — indentation and line length — and leave keys where they are. Sorting reorders object keys to a canonical order while keeping the meaning identical. They are independent and compose well: sort, then format or minify.

How are edge cases like duplicate or numeric-looking keys handled?

The comparison is alphabetical and character by character, not numeric, so "item10" sorts before "item2". JSON object keys are strings, and standard parsing keeps the last value for a repeated key. If the input is not valid JSON, you get an error instead of a partial result.

Does sorting the keys change what my JSON means?

No. JSON objects are unordered, so reordering keys produces an equivalent document. Sorting simply gives you one canonical text form of the same data, which is what makes diffs and comparisons stable.

Can it sort keys inside an array of objects?

Yes. The array keeps its element order, but every object inside it has its own keys sorted, so a list of records is normalized field by field while the records stay in sequence.

Where does the sorted JSON go next?

Copy it straight from the tool, or open it in the full editor to format, minify, validate, visualize it as a tree or mind map, and use the AI copilot on it.

Related tools

Sort your JSON keys

Open the Editor