Skip to content
ToolPlankDEV
JSON Tools
100% In-Browser Execution

Updated:

Sort JSON Keys

Paste JSON and sort json keys in one step. The tool orders every object alphabetically, shows which keys moved, keeps long numbers exactly as written, can pin keys like name and version first, and warns about repeated keys. Nothing is uploaded.

Options:

Set Arrays to Sort objects by a key to use this

JSON

Input
0 chars · 0 lines

Sorted JSON

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

What moved

Which keys changed place, repeated keys and exact long numbers are listed here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use Sort JSON Keys

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your JSON

    Paste it into the left box, press Paste, or open a .json file. Sample loads a package.json style object. Translations and API records load other examples.

  2. 02

    Read the sorted JSON and what moved

    The sorted JSON appears on the right as you type. The What moved panel lists each object whose keys changed place, with the old and new position of the keys. A mistake in your JSON is reported with its line and column.

  3. 03

    Choose the order

    Pick code point, case-insensitive or natural order, ascending or descending, every level or only the top one. Pin keys such as name and version to the start, and decide whether arrays are sorted.

  4. 04

    Copy or download

    Press Copy to paste the result into your file, or Download to save it as sorted.json.

How to sort JSON keys alphabetically

JSON objects have no required key order, but files that people read and compare do. To sort json keys alphabetically, the tool reads your JSON, orders the keys of every object, and writes it back with the layout you choose. Values are not touched.

The built-in sample is a package.json style object on one line. With the default options it becomes:

JSON
{
  "dependencies": {
    "axios": "^1.7.0",
    "react": "^18.3.1",
    "zod": "^3.23.0"
  },
  "devDependencies": {
    "typescript": "^5.5.0",
    "vitest": "^2.0.0"
  },
  "engines": {
    "node": ">=20"
  },
  "id": 9007199254740993123,
  "name": "demo-app",
  "scripts": {
    "build": "vite build",
    "dev": "vite",
    "lint": "eslint .",
    "test": "vitest"
  },
  "version": "1.2.0"
}

The status line reports 5 objects and 15 keys moved. The What moved panel gives the detail for each object, for example axios 3 to 1 and zod 1 to 3 inside the dependencies. That is what makes a pull request easy to review: you can see which changes are only reordering.

Code point, case-insensitive and natural order

Code point order compares the character codes, so every capital letter comes before every lowercase letter. It matches Python's sort_keys and a sorted JSON.stringify, which makes it the right choice when another tool must produce the same file.

JSON
{"A":4,"B":2,"a":3,"b":1}

Case-insensitive order ignores capitals, so A and a sit together:

JSON
{"A":4,"a":3,"B":2,"b":1}

Natural order reads digit runs as numbers, so item2 comes before item10. It also ignores capitals. Use it for translation keys and anything numbered:

JSON
{"item1":3,"item2":2,"Item3":4,"item10":1}

When two keys are equal in the chosen order, the one that came first in your file stays first.

Pin keys first and sort one level or all levels

Some files read better with a fixed head. Type name,version in Pin keys first and those keys stay at the start of the top-level object in that order, then everything else is sorted:

JSON
{"name":"app","version":"1.0.0","license":"MIT","scripts":{}}

Pinned names apply to the top-level object, and to each object when the top level is an array. Nested objects are sorted normally. Set Levels to Top level only if inner objects should keep the order they have now.

Sort JSON object by key inside arrays

Arrays keep their order by default, because the order of items often carries meaning: steps, a ranking, coordinates. Two options change that on purpose. Sort plain values orders arrays that hold only numbers, text or true, false and null. Sort objects by a key orders an array of records by the value of one key, such as id.

JSON
[{"id":1,"name":"Ann"},{"id":2,"name":"Bo"},{"id":3,"name":"Cy"}]

That is the result for three records entered in the order 3, 1, 2 with the key set to id. Numbers sort by value, text uses the chosen order, and records without the key go last. The sort is stable, so records with the same id keep their order.

Long numbers, strings and repeated keys

Many sorters parse the JSON into JavaScript values and print it again, which rounds numbers beyond 15 or 16 digits. This tool moves the original text of every value instead. In the sample, 9007199254740993123 comes out as 9007199254740993123, and 1.0, 1E+5 and 0.10 keep their form. Strings keep their escapes too, so \u00e9 stays \u00e9.

A repeated key is not merged or dropped. Both copies stay, in their original order, and the Repeated keys list names the object. Most readers use the last copy, so you may want to remove one by hand.

Pretty output ends with a line break, like a file saved by most editors. Minified output does not.

Sort JSON keys in Python, JavaScript and on the command line

  • Python: json.dumps(data, sort_keys=True, indent=2) sorts keys in code point order.
  • JavaScript: JSON.stringify has no sort option. You rebuild each object with its keys in order, and keys that look like whole numbers, such as "10", are always listed first by the language.
  • Command line: jq -S . file.json sorts keys.
  • Editors: VS Code's built-in Sort Lines Ascending sorts lines, which breaks nested objects. Use this page, or a JSON-aware extension.

This page is handy when you do not want to write code, when the file holds secrets you will not paste into a chat, or when you want to see which keys moved.

Limits and privacy

The input must be valid JSON. Comments and trailing commas are accepted only when Allow comments and trailing commas is on, and they are removed from the output, because JSON has no place for them. JSON5 and other dialects are not supported, and the tool does not check a schema.

Sorting runs in your browser and nothing is uploaded. The Privacy Policy has the details.

Need to clean text inside the values? Use JSON Escape and JSON Unescape. To change the format, try JSON to YAML or JSON to TOML. To order plain lines, use Sort Lines, and to compare two lists, use Compare Two Lists.

Frequently Asked Questions

Technical Q&A for Sort JSON Keys

Common questions about edge cases, character encoding, and privacy guarantees.

No. A JSON object is a set of named values, so reordering the keys does not change the data. The only exception is a program that depends on key order, which is rare and fragile.

Not by default. Arrays keep their order because the order of items usually means something. You can turn on sorting for plain values, or sort objects by one key.

Code point order compares character codes, and capital letters have lower codes than lowercase ones. Switch Order to Ignore capitals if you want A and a together.

Use json.dumps(data, sort_keys=True, indent=2). It gives the same order as the Code point option on this page.

JSON.stringify cannot sort, so you rebuild each object with Object.keys(obj).sort(). Keys that look like whole numbers are always placed first by JavaScript, which this page does not do.

VS Code has no built-in command for it. Sort Lines Ascending only orders whole lines and breaks nested objects. Paste the JSON here, or install a JSON sorting extension.

No. Each value is copied as the exact text you pasted, so numbers with 20 digits, 1.0 and 1E+5 come out unchanged. The notes tell you when a number was longer than 15 digits.

Both copies stay in the output, in their original order, and the Repeated keys list shows which object has them. Most JSON readers use the last copy.

Yes. Type name,version in Pin keys first. Those keys stay at the start of the top-level object in that order and the rest is sorted.

No. Sorting runs in your browser and nothing is sent to a server.