jsontoolskit.org
JSON and JSON Schema utilities, in the browser
Say hi →

Sort a JSON Array

multi-field · numeric · date · natural order · stable

Sort an array of objects by a field — or by several, tie-breaking left to right. Comparison is type-aware: numbers compare as numbers rather than as strings, so 9 sorts before 10; dates parse before comparing; and text uses natural order, which puts item2 before item10. The sort is stable, so records that tie keep the order they arrived in.

Paste input to start.

How to sort a JSON array

  1. Paste a JSON array at the top level.
  2. Name the field to sort by. Dotted paths work — user.lastName — and so do bracket indexes, scores[0].
  3. For a multi-level sort, comma-separate: country,city sorts by country and breaks ties by city.
  4. Leave the field blank to sort the array's elements themselves, which is what you want for an array of strings or numbers.
  5. Copy or download. The status bar reports how many records were missing the first sort field.

Why "auto" is usually right

Auto compares two values as numbers when both are numbers, and otherwise falls back to natural text order. That handles the common mixed case — a version column of 1.9, 1.10, 1.11 sorts the way a human expects, and a numeric column sorts numerically even if some values arrived as strings.

Force the type when auto guesses wrong. Number coerces both sides, so "100" and 100 sort together. Date parses ISO 8601 and anything else the browser accepts, which is the only way 2026-01-02 and 2026-1-2 compare equal. Lexical is plain code-point order — the fastest and the one that puts Z before a.

Nulls, missing fields and stability

A record missing the sort field is not the same as a record whose field is null, but for ordering purposes both are "nothing to compare". By default they collect at the end regardless of direction, which keeps them out of the way; turn the checkbox off and they sort to the front. Either way they never interleave with real values.

The sort is stable: two records with equal keys stay in their original relative order. That is what makes multi-pass sorting work — sort by city, then sort by country, and you get the same result as sorting by both at once. It also means re-running the tool on its own output is a no-op rather than a reshuffle.

Privacy

Nothing is uploaded. The sort runs in this tab using your own browser's JavaScript engine — no server sees your data, and the page keeps working with the network disconnected.

FAQ

Can I sort the keys inside each object instead?

That's a different axis — use Sort keys, which recursively alphabetises object keys for stable diffs. This page orders the array's elements and never touches key order.

How do I sort by a field that only some records have?

It works — the records without it collect at one end according to the nulls setting. If you want to see them separately first, Filter array with field missing.

Does descending reverse the tie-breaking too?

Yes. Direction applies to every field in the list. For a mixed order — country ascending, revenue descending — sort by revenue descending first, then by country ascending; stability preserves the first sort inside each country.

What happens to nested arrays or objects in the sort field?

They are compared by their RFC 8785 canonical form, so the comparison is deterministic and key order does not affect it. It is rarely a meaningful ordering — point at a scalar field instead.