toolqik

129 · JSON

JSON Array Sorter

Sort a JSON array by value or by a field, with natural, numeric or text ordering.

Runs in your browser
Order
Compare as
Options
Indent
Sorted JSON

  

About this tool

Sort a JSON array without writing code. Paste JSON, pick the array (or let the tool find the first one), name the field to sort by, and get the whole document back with that array in order. Sorting by a field works on nested fields too: stock.warehouse sorts by the warehouse value inside each item’s stock object.

How values are compared

  • Auto (natural): numbers sort numerically, and strings sort naturally, so "Item 2" comes before "Item 10" (a plain text sort would put “10” first). Accents are handled the way people expect: Ítem sorts with Item.
  • Numbers: also sorts numeric strings such as "9.99" and "120" by their value.
  • Text: compares everything as text, character by character.
  • Items where the field is missing or null always go last, in both directions, so they don’t crowd the top of a descending list.
  • The sort is stable: items that compare equal keep their original order, so you can sort by one field and then another.

Choosing the array

Leave Array to sort blank to sort the top-level array, or the first array found in an object (such as products in {"products": [...]}). To pick a specific one, enter its path, like $.data.items or data.items. Paths follow JSONPath; the JSON viewer shows the path of any array you click.

Sorting in code

// JavaScript: by a field, natural order, missing values last
const coll = new Intl.Collator(undefined, { numeric: true });
items.sort((a, b) => (a.name == null) - (b.name == null) || coll.compare(a.name, b.name));

# Python
items.sort(key=lambda x: (x.get("price") is None, x.get("price")))

# jq
jq '.products |= sort_by(.price)' data.json

FAQ

How do I sort a JSON array by a key?

Paste the JSON, enter the key in “Sort by field” (for example price or user.name), and choose ascending or descending. The array is sorted in place and the whole document is returned.

Can I sort by a nested field?

Yes. Use dots for nested fields, for example address.city or stock.warehouse.

How do I sort an array of strings or numbers?

Leave “Sort by field” blank to sort by the items themselves.

Why does “Item 10” come after “Item 2”?

Auto mode uses natural ordering, which compares the numbers inside text by value. Choose Text to sort strictly character by character instead.

Where do null and missing values go?

Always at the end, whether you sort ascending or descending.

Can it remove duplicates?

Yes. Turn on “Remove duplicate items” to keep only the first of any identical items.

esc
↑↓ navigate↵ open