Skip to content
Tools

JSON Sorter: Sort JSON Keys A-Z or Z-A

Last updated:

A JSON sorter reorders the keys of every object alphabetically, so two files that hold the same data end up as identical text. Pick A-Z or Z-A, sort every level or only the top one, and optionally sort arrays too: plain lists by value, lists of objects by one key such as id.

Runs in your browser: the JSON you sort never leaves your device – nothing is uploaded, logged or stored on a server. How we protect your data

100% in-browserNothing is uploaded

Input

Loading editor…

Paste JSON to sort

or drop a file anywhere in this box. Everything stays in your browser.

Drop a file to load it

Output

Loading editor…

Sorted JSON appears here

Results update as you type.

How to use the JSON Sorter

  1. Paste JSON or drop a .json file into the input, or press Sample data.
  2. Pick the key order above the editors: A-Z or Z-A.
  3. Open Options. Leave "Sort nested levels too" on for every level, or turn it off to sort only the outermost object.
  4. To sort arrays, choose "Sort strings and numbers" for lists of plain values, or "Sort objects by a key" and type the key, for example id.
  5. Copy the result or download sorted.json. The line above the output says how many objects and arrays moved.

Worked example

A config with a mixed-case key and a list of users

Input

{"version":"2.1","users":[{"name":"Zoe","id":3},{"name":"Ada","id":1}],"Config":{"timeout":30,"retries":3},"active":true}

Sorted (A-Z, every level)

{
  "Config": {
    "retries": 3,
    "timeout": 30
  },
  "active": true,
  "users": [
    {
      "id": 3,
      "name": "Zoe"
    },
    {
      "id": 1,
      "name": "Ada"
    }
  ],
  "version": "2.1"
}

Config comes first because A-Z compares character codes, and capital letters have lower codes than lowercase ones. Tick Ignore upper/lower case to get active, Config, users, version instead. The users array keeps Zoe before Ada: arrays are only reordered when you ask for it.

What each option reorders

What each option reorders
OptionWhat gets reorderedWhat stays as it is
Key order A-Z / Z-AKeys of every object, or only the outermost object when nested levels are offArray order and all values
Ignore upper/lower caseKeys compare as if lowercase, so a, B, c stay togetherThe exact spelling of each key
Arrays: sort strings and numbersArrays that hold only strings, numbers, true/false and null, in the order null, false, true, numbers, textArrays that contain objects or other arrays
Arrays: sort objects by a keyArrays where every item is an object, by the value of the key you name; items without that key go lastMixed arrays; the keys inside each object still follow A-Z / Z-A
IndentWhitespace of the output onlyThe data

When sorted keys help, and when to leave them alone

Sort keys when JSON lives in version control, snapshot tests or fixtures that code generates. Generators often write keys in insertion or hash order, so a regenerated file can show every line as changed when only one value moved. Sorted output keeps a diff down to the real changes, and two services that emit the same data in different key order produce byte-identical files.

Leave sorting off when order carries meaning for people, such as package.json (name and version first) or an OpenAPI document, or when the reader is order-sensitive. JSON objects are formally unordered, but some tools still depend on the order. A hash or signature computed over the raw text also changes when keys move, so sort before you sign, not after.

How values are compared

Keys are compared by UTF-16 code units, the same rule as the default sort in JavaScript, which is why Zebra comes before apple until you ignore case. Numbers inside sorted arrays are compared by value, and integers beyond 2^53 are compared exactly: 12345678901234567891 sorts after 12345678901234567890 and both are written back with every digit.

Mixed arrays follow one fixed order, borrowed from jq: null, false, true, numbers, strings. Arrays of objects, or of arrays, are skipped by "Sort strings and numbers" so a list of records is never shuffled by accident; use "Sort objects by a key" for those.

JSON Sorter FAQ

How do I sort JSON keys alphabetically?

Paste the JSON and leave Key order on A-Z; the output updates as you type. Choose Z-A for reverse order. Turn off "Sort nested levels too" if only the outermost object should change.

Does sorting keys change the meaning of my JSON?

Not for a parser: RFC 8259 calls an object an unordered collection of members, so {"a":1,"b":2} and {"b":2,"a":1} hold the same data. It does change the text, so a checksum or signature over the raw file will differ, and a person or tool that reads keys in order sees a different layout.

Can I sort the items inside an array?

Yes, on request. "Sort strings and numbers" orders arrays of plain values, and "Sort objects by a key" orders a list of records by a key such as id or name, placing records without that key last. Arrays are never reordered by default, because position is part of an array's meaning, as in a coordinate pair [lon, lat].

Why are uppercase keys sorted before lowercase ones?

A-Z compares character codes, and every capital letter has a lower code than every lowercase letter, so Zebra comes before apple. Tick Ignore upper/lower case for dictionary order.

How do I sort JSON keys in code or on the command line?

jq -S . file.json sorts every object, and Python does it with json.dumps(obj, sort_keys=True). JSON.stringify has no sort option, so JavaScript needs a replacer that rebuilds each object with sorted keys. jq and JavaScript read numbers as 64-bit floats, so integers above 9,007,199,254,740,991 can be rounded on the way; this page keeps the original digits.

Will sorting change my numbers or strings?

No. Only the order of keys, and of arrays if you choose to sort them, changes. Numbers are copied as written, so 12345678901234567890, 1.0 and 1E+2 come out exactly as typed, and strings keep their escapes such as \u00e9.

Related tools

Learn more