FormatterHQ

JSON Sorter

Sort the keys of every object in your JSON, ascending or descending, with natural ordering for numbers in key names. Optionally sort simple arrays too.

Input JSON
Output JSON
Ready.

How to use the JSON Sorter

  1. Paste the JSON you want to sort, or load it with Upload file or Load URL.
  2. Pick an Order: A → Z or Z → A.
  3. Tick Also sort arrays of values if arrays of strings or numbers should be ordered too, and choose an Indent.
  4. Click Sort (Auto update re-sorts as you type), then Copy or Download the result.

A JSON sorter for predictable key order

JSON objects are unordered by definition, yet the order in which keys are written matters a great deal to people. Two files with the same data in a different order produce a noisy diff, and a long config is hard to scan when keys appear at random. This JSON sorter rewrites every object with its keys in alphabetical order, at every nesting level, so the same data always produces the same text.

Example

Input:

{"version":"2.1.0","name":"svc","deps":{"zod":"^3","Express":"^4","axios":"^1"},"files":["item10","item2","Item1"],"sizes":[10,9,100]}

Sorted A → Z with Also sort arrays of values ticked:

{
  "deps": {
    "axios": "^1",
    "Express": "^4",
    "zod": "^3"
  },
  "files": [
    "Item1",
    "item2",
    "item10"
  ],
  "name": "svc",
  "sizes": [
    9,
    10,
    100
  ],
  "version": "2.1.0"
}

With the checkbox cleared, the keys are sorted the same way but files and sizes keep their original order.

How the comparison works

  • Case-insensitive. Express sorts between axios and zod rather than before all lowercase keys, which is how a person would alphabetize. Keys that differ only in case, such as B and b, are still placed in a consistent order.
  • Natural numbers. Digits inside names are compared as numbers, so item2 comes before item10. A plain character sort would put item10 first.
  • Z → A reverses the result at every level.

What "Also sort arrays of values" does

Arrays are ordered lists, and in most data their order means something, so they are left alone by default. When the option is ticked, an array is sorted only if every element is a simple value: a string, number, boolean or null. Numbers are compared numerically, so [10, 9, 100] becomes [9, 10, 100]. Arrays that contain objects or other arrays are never reordered, although the keys inside those objects are still sorted.

Use the option for sets stored as arrays, such as tags, permissions or feature flags, where only membership matters.

One ordering rule you cannot override

Keys that look like whole numbers, such as "2" and "10", are always placed first in ascending numeric order, even with Z → A selected. JavaScript objects store integer-like keys that way, and the output is written from a JavaScript object. Other keys follow in the order you chose.

Why sort JSON?

  • Smaller diffs. Sort both versions of a file before comparing them in the JSON diff tool, and only real changes remain.
  • Consistent configs. Committing sorted translation files, feature-flag lists and settings keeps merge conflicts down when several people edit them.
  • Faster review. A reviewer can check that an expected key exists without searching.
  • Spotting near-duplicates. Keys like userId and userID end up next to each other.

Note that this is not the canonical form defined by RFC 8785 (JSON Canonicalization Scheme), which orders keys by raw UTF-16 code units and is used for hashing and signatures. Use this sorter for readability, not for producing signed payloads.

If you only need sorted keys as part of formatting, the Sort keys checkbox in the JSON formatter does the same for objects. Sorting runs entirely in your browser; your data is only sent to our server when you use Load URL or Save & Share.

Frequently asked questions

Does sorting JSON keys change the meaning of the data?
No. The JSON specification treats objects as unordered, so any compliant parser reads sorted and unsorted versions as the same data. Only array order is meaningful, which is why arrays are left untouched unless you ask otherwise.
Can I sort an array of objects by a field, like name or date?
Not with this tool. It sorts keys within objects and, optionally, arrays of simple values. Sorting records by a field requires code, for example items.sort((a, b) => a.name.localeCompare(b.name)) in JavaScript.
Why are numeric keys at the top even when I choose Z → A?
Keys such as "1" or "42" are treated as integer indexes by JavaScript objects and always listed first in ascending order. The rest of the keys follow the order you selected.
Is the sort case-sensitive?
No. Uppercase and lowercase letters are compared as equal first, so Apple, banana and Cherry sort in dictionary order. Only when two keys are identical apart from case is a fixed tie-break applied.

Last updated September 26, 2026

Related tools

JSON Stringify Online Stringify JSON into an escaped string literal, exactly like JSON.stringify. Ready to embed JSON inside JSON, code or config values. JSON Syntax Highlighter Syntax highlight JSON with light, dark or Monokai themes and copy the colourised HTML for blogs, docs and slides. JSON to JSONL Converter Convert a JSON array to JSON Lines (JSONL / NDJSON), one record per line, for streaming, logging, BigQuery and ML datasets. JSON to One Line Convert multi-line JSON to a single line. Collapse formatted JSON for logs, CLI arguments, environment variables and CSV cells. JSON to PHP Array Converter Convert JSON to a PHP array literal with short [] or array() syntax, ready to paste into Laravel config files, seeders and tests. JSON to String Converter Convert JSON to a single escaped string you can paste into code, databases or other JSON documents. Choose double, single or no quotes. JSON Tree Viewer Display JSON as an expandable tree. Collapse and expand objects and arrays to understand deeply nested data structures. JSON Unflatten Rebuild nested JSON from flat dot-notation keys (a.b.c) or bracket paths (a[0].b), the reverse of JSON flatten. JSON Validator Validate JSON online and find syntax errors fast. Get the exact line and column of each problem and fix broken JSON in one click. JSON Viewer & Beautifier View JSON as a collapsible tree and beautify it at the same time. Explore nested objects and arrays without losing your place. JSON5 Formatter Format and beautify JSON5 with comments, unquoted keys and trailing commas, or convert JSON5 to strict JSON. JSON5 Validator Validate JSON5 syntax online. Check config files with comments and trailing commas and get line and column for each error.