JSON Sort

Sort JSON object keys alphabetically (A-Z or Z-A), or sort a JSON array of objects by any field.

Sort by:Order:
Input (JSON)
Loading editor…
Sorted Output
Loading editor…
Size: 0 bytesLines: 0

Two Ways to Sort JSON

JSON objects are technically unordered — the specification does not require keys to appear in any particular sequence, and most parsers preserve whatever order the source used. In practice, though, order matters to people: it affects how easy a document is to scan, and it directly affects line-by-line diffs between two versions of the same data. This tool covers two different, common needs.

Sort Object Keys recursively walks every object in a document and rewrites its keys in alphabetical order (A–Z or Z–A), at every level of nesting — not just the top level. Arrays are left untouched, since array item order is part of the data itself, not incidental formatting.

Sort Array by Field is for the opposite case: a JSON array of objects — search results, a list of records, rows from an API — where you want to reorder the itemsby one of their fields, like sorting a spreadsheet column. Pick any field present in the array and a direction, and the items are reordered by that field's value.

Both modes run entirely in your browser. Paste any JSON — an API response, a config file, a snapshot from a test — or drag and drop a .json file.

Why Sort JSON?

Clean Diffs

When two JSON documents use a different key order, a diff tool flags every line as changed even if the data is identical. Sorting keys first gives you a diff that only shows real changes.

Comparing API Responses

Two responses with the same fields in a different order look different at a glance. Sorting normalizes the order so you can compare them side-by-side or with a text diff.

Config File Reviews

Config files edited by hand or by different tools tend to drift in key order over time. A consistent, alphabetical order makes config reviews faster and version control history cleaner.

Deterministic Output

Some pipelines (hashing, caching, snapshot testing) need JSON output to be byte-for-byte deterministic. Sorting keys removes key order as a source of non-determinism.

Ranking Records by a Field

An API response, export, or test fixture often arrives as a list of records in insertion order. Sorting the array by a field — price, date, score, age — turns it into a ranked or chronological list without writing a script.

Example: Sort Object Keys

Keys sorted alphabetically at every level. Notice the charlie and mango arrays keep their original order.

Before sorting
{"zebra":1,"apple":{"delta":4,"bravo":2,"charlie":[3,1,2]},"mango":["b","a","c"]}
After sorting
{
  "apple": {
    "bravo": 2,
    "charlie": [
      3,
      1,
      2
    ],
    "delta": 4
  },
  "mango": [
    "b",
    "a",
    "c"
  ],
  "zebra": 1
}

Example: Sort Array by Field

The same array of people, reordered by ageascending. The object keys themselves are left exactly as they were — only the array's item order changes.

Before sorting
[
  { "id": 1, "name": "Tom Cruise", "age": 61 },
  { "id": 2, "name": "Justin Timberlake", "age": 42 },
  { "id": 3, "name": "Elon Musk", "age": 52 }
]
After sorting by "age" (ASC)
[
  { "id": 2, "name": "Justin Timberlake", "age": 42 },
  { "id": 3, "name": "Elon Musk", "age": 52 },
  { "id": 1, "name": "Tom Cruise", "age": 61 }
]

Features

Recursive Key Sorting

Every nested object in the document has its keys sorted alphabetically, not just the top level.

Sort an Array by Field

Pick any field from an array of objects — e.g. age or name — and reorder the array by that field’s value.

Ascending or Descending

Toggle sort direction for either mode: A–Z or Z–A for keys, lowest-to-highest or highest-to-lowest for field values.

Upload a File

Drag and drop or upload a .json file to sort it directly, no copy-pasting required.

Copy

Copy the sorted output to your clipboard with a single click.

Download

Save the result as a standalone .json file for use in your project.

Related Tools