On-device AI — professional-grade, fully private.

JSON Key Sorter

Sort JSON keys without touching a single value.

  • No upload
  • Values stay byte-exact
  • Duplicate keys kept
  • JSON, JSONC & NDJSON

Drop a JSON file here

JSON, JSONC, NDJSON or JSON Lines · up to 25.0 MB

Sort settings
Presets
Sort order
Sort order
Direction
Depth
Depth

Arrays do not count as a level, so “Top level only” sorts each record of a list.

Advanced
Output
Indent
Batch
Pro

Free sorts one document at a time.

What this JSON key sorter does

Alphabetize JSON object keys recursively to create stable, diff-friendly output while preserving array order and clean formatting. Nested objects are processed recursively; array element order is left unchanged unless you ask for it. Paste, upload, or drag-and-drop; invalid JSON shows the line, the column and a caret at the problem, with links to the Formatter and the Validator. Choose 2 spaces, 4 spaces, tab or minified output, then download the file or copy the result.

  • Three orders — alphabetical, natural (so item2 comes before item10), or by key length, in either direction.
  • Pinned keys — list the fields that should sit at the top and they stay there, at every level, with the rest ordered beneath them.
  • A depth limit — sort every level, only the outermost, or as far down as you choose.
  • Byte-exact values — large integers, 1.0, 1e5 and escaped characters come out exactly as they went in.
  • Duplicate keys kept — both members survive and are counted, or you can drop one on purpose.
  • Comments and JSON Lines — JSONC comments move with the key they describe, and one-document-per-line files are sorted line by line.

Sorting runs off the page's main thread, so the interface keeps responding while a large document is processed.

What the sorter never changes

Almost every JSON tool works the same way: parse the document into memory, rearrange it, and serialise it back out. That round trip is not free, and the losses are silent — the file looks fine, it is valid JSON, and it no longer says what it used to. This tool edits the text instead, copying every value across character for character, so five things survive that would otherwise not.

  • Large integers — an identifier like 12345678901234567890 comes back with all twenty digits. A parsed copy returns 12345678901234567000, because it went through a floating-point number on the way.
  • How a number is written — 1.0 stays 1.0, 1e5 stays 1e5 and 0.10 keeps its trailing zero. A round trip rewrites all three.
  • Duplicate keys — a document with the same key twice keeps both. A parser keeps only the last, and nothing warns you.
  • String escapes — a key or value written as \u00e9 stays that way rather than being re-spelled as the character it denotes.
  • Number-like keys — a key called "10" stays where the sort put it. Rebuilt in memory it is treated as an array index, hoisted above every other key and re-ordered by size, whatever order was asked for.

Choosing a sort order

Which order is right depends on what will read the file next, so all three are one click apart and none of them is hidden behind an upgrade.

  • Alphabetical — compares keys as text, character by character. This is what a diff tool, a schema and most style guides expect, and it is the default.
  • Natural — reads digits inside a key as numbers, so item2 sorts before item10 rather than after it. Useful whenever keys are numbered.
  • Key length — shortest first, ties broken alphabetically. Handy for scanning a wide configuration object where the short keys are the ones you set.
  • Ignore case — folds capitalisation so Name and name sit together instead of in two separate blocks, with the original spelling used only to break a tie.
  • Direction — either order can be reversed. Pinned keys stay pinned; reversing the rest does not push them to the bottom.
  • By value — orders each object's members by what they hold rather than by what they are called. Values group by type — null, then booleans, then numbers, then text — and sort within it; a member holding an object or a list has no simple value and goes last.

Pinning the keys that matter

A purely alphabetical file is consistent but not always readable: the field you look for first ends up wherever the alphabet puts it. Listing keys in Pin these keys first puts them at the top in the order you wrote them, then sorts everything else beneath them.

  • Every level — a pinned key is pinned wherever it appears, not only in the outermost object.
  • Prefix matching — a trailing asterisk matches a family of keys, so x-* keeps every extension field together at the top.
  • First match wins — listing name before n* pins name above nickname rather than letting the wildcard claim it.
  • A ready-made list — the package.json preset fills the box with the fields that file conventionally opens with, so a project manifest sorts the way reviewers expect.

How deep the sort goes

Sorting the whole tree is usually what you want, but not always: a configuration file often has a meaningful order inside its sections that should survive while the sections themselves are put in order. Depth controls exactly that.

  • All levels — every object in the document, however deeply nested. The default.
  • Top level only — the outermost object's keys move and nothing beneath them does.
  • A chosen number of levels — sort two or three levels down and leave the rest as written.
  • Arrays are transparent — an array does not use up a level, so Top level only on a list of records sorts the keys inside each record. Counting arrays would make the setting do nothing at all on the most common shape there is.

Duplicate keys, and what to do with them

JSON allows the same key twice in one object. Parsers do not: they keep one and discard the rest, usually silently, which is why a duplicate can survive several tools and only be noticed when a value goes missing. This sorter counts them and shows the number, and lets you decide.

  • Keep all — both members are written out, next to each other after sorting. The document keeps everything it arrived with. This is the default.
  • Keep first — the earliest occurrence of each key is kept and the later ones removed, with the count reported.
  • Keep last — the final occurrence wins, which is what a JavaScript parser would have done anyway, but visibly and on purpose.
  • Applied everywhere — removal is not limited by the depth setting. Asking for duplicates to be removed means everywhere in the document, not only as far down as the sort reaches.

Arrays, and when they move

Array position carries meaning, so nothing reorders an array unless you turn it on. Two settings do, and both only act when the whole array fits the rule — a partly-sorted array would be output nobody could predict from the control that produced it.

  • Sort arrays of plain values — reorders arrays whose elements are all strings, numbers, booleans or null. Values group by type, then sort within it.
  • Sort lists of objects by a property — name a field such as id and a list of records is ordered by it. Records missing that field keep their relative order at the end.
  • Keys inside arrays always sort — the keys of an object inside an array follow the ordinary rules whether or not either array setting is on. Only the position of the elements themselves is protected.

Files this tool opens

Four extensions, and anything the tool cannot open is refused at the file dialog with the reason and a route out, rather than accepted and failed halfway through.

  • .json — one JSON document, read strictly. Comments and trailing commas are refused unless you turn them on, because accepting them silently would make the tool disagree about what valid JSON is.
  • .jsonc — JSON with comments and trailing commas, the flavour tsconfig.json and VS Code settings use. Comments stay attached to the key beneath them and move with it when it moves.
  • .ndjson and .jsonl — one document per line. Each line is sorted on its own and written back on its own line, so the output is still valid JSON Lines; the indent setting does not apply and the tool says so.
  • .txt — accepted so a document saved without an extension still opens. Its contents still have to be JSON.

How to sort JSON keys

Four steps, and only the first two are needed for the common case.

  1. Add your JSON — Drop a .json, .jsonc, .ndjson or .jsonl file onto the page, browse for one, or paste JSON into the box below the drop area. The document is read on your device and never uploaded.
  2. Choose an order — Pick alphabetical, natural or key-length order and a direction. Turn on Ignore case if capitalisation should not decide position, and set how deep the sort goes.
  3. Set anything advanced — Open Advanced to pin keys to the top, choose what happens to duplicate keys, sort arrays of plain values, sort a list of objects by one of its properties, or accept comments and trailing commas.
  4. Sort, then download or copy — Press Sort keys. Choose 2 spaces, 4 spaces, tab or minified output, then download the file or copy the result. Change any setting and the result is marked as using older settings so you can re-apply.

Options at a glance

  • Sort order — alphabetical, natural or key length, ascending or descending, with an option to ignore case.
  • Depth — all levels, top level only, or a chosen number of levels. Arrays do not count as a level.
  • Pin these keys first — a comma-separated list, with a trailing asterisk for prefix matching.
  • Duplicate keys — keep all, keep first or keep last, with the number removed reported.
  • Array sorting — optionally sort arrays of plain values, or lists of objects by a named property.
  • Accept comments and trailing commas — read JSONC instead of strict JSON.
  • Read the input as — detect automatically, or force one JSON document or JSON Lines.
  • Output — 2 spaces, 4 spaces, tab or minified, with an optional trailing newline.
  • Download and copy — save the sorted document, or copy it to the clipboard. Pro users can download a whole batch as one archive.

Frequently asked questions

How does sorting JSON keys work?

The tool reads your JSON, works out where every key and every value sits in the text, and writes the document back out with each object's members in the order you asked for. Because it works on the text rather than on a parsed copy, the values are carried across unchanged and only the order and the layout are new. The result is valid JSON you can download or copy.

Are nested objects sorted too?

Yes, by default. Sorting is recursive: every object at every depth has its keys ordered, including objects inside arrays. If you only want the outer level touched, set Depth to Top level only, or pick a number of levels. Arrays do not count as a level, so Top level only on a list of records sorts the keys inside each record.

Are array elements reordered?

No, not unless you ask. Array order carries meaning, so by default only object keys move. Two opt-in settings change that: one sorts arrays whose elements are all plain values, and one sorts a list of objects by a property you name, such as id. Both are off until you turn them on, and both leave any array that does not match the rule exactly as it was.

Does sorting change my values?

No. Values are copied straight out of your file, character for character. That matters more than it sounds: a tool that parses JSON and re-serialises it turns 12345678901234567890 into 12345678901234567000, rewrites 1.0 as 1 and 1e5 as 100000, and re-spells escaped characters. None of that happens here, so a sorted file differs from the original only in the order of keys and in whitespace.

What happens to duplicate keys?

They are kept, and counted. Most JSON tools quietly drop all but the last one, because the parser they use collapses them before the tool ever sees them. Here both members survive and appear next to each other in the result. If you would rather remove them, set Duplicate keys to Keep first or Keep last and the tool reports how many it removed.

Can I put certain keys at the top?

Yes. Open Advanced and list them in Pin these keys first, separated by commas. They appear in the order you list them, above everything else, at every level of the document. A trailing asterisk matches a prefix, so x-* pins every extension field. The package.json preset is this feature pre-filled with the fields that file conventionally starts with.

What is natural order?

Natural order reads runs of digits inside a key as numbers, so item2 comes before item10. Plain alphabetical order compares them as text, where 1 sorts before 2 and item10 therefore comes first. Both are correct for different jobs: alphabetical is what most diff tools and schemas expect, natural is easier to read when keys are numbered.

Can it read files with comments, or one document per line?

Yes to both. Turn on Accept comments and trailing commas in Advanced to read JSONC, the flavour used by tsconfig.json and VS Code settings; comments stay attached to the key they sit above and move with it. Files with one JSON document per line, such as .ndjson and .jsonl exports, are detected automatically and each line is sorted on its own.

Is my JSON data secure?

Yes. The whole sort happens on your device, so nothing is uploaded and no copy of your document exists anywhere else. That means you can safely sort private configuration, API responses and customer data, and the tool keeps working with no network once the page has loaded.

Why sort JSON keys, and how large a file can I use?

Key order is not guaranteed across languages, libraries or serialisers, so two exports of the same data can differ only in ordering and fill a code review with noise. A stable order makes a diff show real changes. Free sorts one document up to 25 MB at a time and every sorting feature is included; Pro removes the size cap up to what your device can handle, sorts up to 20 documents at once and returns them as a single archive.

4.8out of 5

from 68 ratings

Rate this tool

Tap a star — it takes a second