Data ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Data Tools

JSON Sorter: Sort Keys Alphabetically

Sort JSON object keys A to Z, Z to A or in natural order at every level, optionally sort array items too, and copy the result pretty-printed or minified.

View all tools
ResultUpdates as you type
{
  "author": {
    "email": "dev@example.com",
    "url": "https://example.com"
  },
  "dependencies": {
    "axios": "^1.7.0",
    "react": "^18.3.0",
    "zod": "^3.23.0"
  },
  "keywords": [
    "tools",
    "json"
  ],
  "name": "demo",
  "version": 2
}

3 objects and 10 keys; every level was sorted.

How to use JSON Sorter: Sort Keys Alphabetically

Paste JSON and the sorted version appears as you type. Choose the order and indent, untick Sort nested objects too to sort only the top level, and tick Also sort array items if array order does not matter. Then press Copy result.

  1. Paste your JSONPaste an object or array into JSON data. Syntax errors are reported with the line, column and a likely cause.
  2. Choose order and indentPick A → Z by character code, case-insensitive A → Z or Z → A, and 2 spaces, 4 spaces, Tab or Minified.
  3. Copy the sorted JSONDecide whether nested objects and arrays are sorted, check the note, then press Copy result.

Sort orders with examples

Sorting {"b":2,"a":{"d":4,"c":3}} gives {"a":{"c":3,"d":4},"b":2}; objects nested inside other objects or arrays are sorted too unless you untick Sort nested objects too. A → Z (character code) compares raw character codes, so digits come before capital letters and capitals before lower case: keys 10, 2, Name, age, item10 and item2 come out in exactly that order. A → Z (case-insensitive, numbers by value) ignores case and reads runs of digits as numbers, giving 2, 10, age, item2, item10, Name. Z → A reverses the character-code order. The note under the result counts the objects and keys that were sorted.

Arrays, big numbers and why sorted keys help

Array items keep their order by default, since order often carries meaning, but objects inside arrays still have their keys sorted. Tick Also sort array items to order the values as well: null and booleans first, then numbers by size, then strings, arrays and objects, so [3,"b",1,null,true,"a"] becomes [null,true,1,3,"a","b"]. Sorted keys make diffs and code reviews cleaner, because two files holding the same data then serialise identically. In recent browsers, integers longer than 15 or 16 digits and long decimals are kept exactly as written; older browsers may round them, and a note says so.

Accuracy and data handling

Keep the original data and spot-check fields, types and delimiters before using an important conversion. The calculation runs in your current browser; the tool code does not send the input to a processing API.

FAQ

Why sort JSON keys?

JSON objects have no guaranteed key order, so different programs may write the same data in different orders. Sorting the keys first means a text diff shows only the values that really changed.

Are array elements sorted too?

Not by default: arrays keep their original order, although objects inside them have their keys sorted. Tick Also sort array items to sort the values themselves.

What if my JSON has an error?

The error shows the line and column, plus a tip for common causes such as single quotes, a trailing comma, comments or unquoted keys. The result updates as soon as the JSON is valid.

Can I minify while sorting?

Yes. Set Indent to Minified (one line) to get sorted JSON on a single line, or choose 2 spaces, 4 spaces or Tab for readable output.

More Data Tools

Related tools