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

Related Tools

Learn more about the JSON Sort

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 items by 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 age ascending. 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.

How to use

Paste your input in the left editor. The output appears automatically on the right. Use the toolbar buttons to copy, download, or transform the result.

  1. Paste or type your content in the input editor on the left.
  2. The formatted output is generated automatically.
  3. Use Copy, Download, or other actions from the output toolbar.
  4. Click the expand icon to view the output in fullscreen.
FAQ

Is this JSON sort tool free?

Yes, it is completely free to use with no limits, signup, or account required.

Is my JSON data uploaded to a server?

No. Sorting runs entirely in your browser using JavaScript, whether you paste JSON or upload a file. Your data never leaves your machine.

What is the difference between "Sort Object Keys" and "Sort Array by Field"?

"Sort Object Keys" reorders the keys within objects, at every level of nesting, and never changes array item order. "Sort Array by Field" does the opposite: it leaves object keys as they are and reorders the items of a JSON array based on the value of a field you choose, like sorting a spreadsheet by column.

Does key sorting only affect the top-level keys?

No. In "Sort Object Keys" mode, every nested object in the document is sorted, at every level of nesting, not just the outermost keys.

Can I sort an array of objects by a specific field, like age or price?

Yes. Switch to "Sort Array by Field", and the tool detects the fields present in your array and lets you pick one from a dropdown, along with ascending or descending order.

Can I choose ascending or descending order?

Yes. Both modes support an ASC/DESC toggle — A-Z or Z-A for object keys, and lowest-to-highest or highest-to-lowest for field values in array sorting.

What happens to items missing the field I sorted by?

Items where the selected field is missing or null are always placed at the end of the result, regardless of sort direction.

Why would I want to sort JSON?

Consistent key order produces cleaner diffs when comparing two versions of a document and is often required for deterministic output in caching or snapshot testing. Sorting an array by field turns a list of records into a ranked or chronological list without writing a script.

Can I upload a file instead of pasting JSON?

Yes. Drag and drop a .json file onto the input panel, or click the upload icon in the panel header to browse for one. Files up to 5MB are supported.

Can I sort large JSON files?

Yes, sorting handles large JSON documents smoothly since everything runs client-side in the Monaco editor, the same editor used in VS Code.

What happens if my JSON is invalid?

The tool shows an error describing exactly what failed to parse, so you can fix the syntax before sorting.