JSON Sort

Sort JSON Arrays
by Any Field

Sort a JSON array of objects by any field — alphabetically, numerically, or by date. Choose ascending or descending order in one click.

Open JSON Sort Tool

Sorted JSON in four steps

Paste your JSON array Drop any JSON array of objects into the input — as compact or pretty-printed as you like.
Click Sort By Find the Sort By button in the Format tab toolbar to start sorting the array.
Enter field name and direction Type the sort key and choose ascending or descending — sort by any string, number, or date field.
Get sorted JSON The sorted array replaces the input immediately. Copy or download the result in one click.

No account. No upload. No nonsense.

🔒

No Server

Your JSON never leaves your device. All sorting runs locally in your browser.

Instant Results

Sorting completes in milliseconds even for large JSON arrays with thousands of records.

📡

Works Offline

Load once and use forever — even on a plane or without internet access.

Related JSON tools

JSON Formatter Pretty-print JSON with syntax highlighting and a collapsible tree view.
JSON Group By Group a JSON array of objects by any field value into a keyed object.
JSON Filter Filter JSON arrays using JSONPath expressions and condition-based queries.
JSON to CSV Export JSON arrays to CSV for spreadsheet analysis and reporting.

Common questions answered

How do I sort a JSON array by a field?

Paste your JSON array in the Format tab, click 'Sort By', enter the field name, and choose ascending or descending. The array is sorted and replaced in the input.

Can I sort by nested fields?

Direct nested field sorting (e.g., address.city) is not yet supported. Flatten the JSON first to bring nested keys to the top level, then sort.

Does my data leave my browser?

No. All sorting runs in your browser — your data never leaves your device.

How are null and missing values handled in sorting?

Records with null or missing values for the sort field are placed at the end when sorting ascending, and at the beginning when sorting descending.

Can I sort a JSON object's keys alphabetically?

Yes — use the 'Sort keys' checkbox in the Format tab toolbar to sort all object keys alphabetically.

What is JSON array sorting?

JSON array sorting reorders elements of a JSON array by a specified field or value. Unlike key sorting (which reorders object properties), array sorting changes the position of elements — typically objects in a list. This is useful when you need to rank, group, or re-sequence data before presenting it or feeding it to another tool.

This tool supports sorting arrays of objects by any nested field, in ascending or descending order. It handles mixed types: numbers sort numerically, strings sort lexicographically, and null values sort to the end. For arrays of primitives (numbers, strings), elements sort by their natural order. The output is valid JSON ready to use.

Sort an array by a field
Input
[
  {"name":"Charlie","age":25},
  {"name":"Alice","age":30},
  {"name":"Bob","age":28}
]
Output
[
  {"name":"Alice","age":30},
  {"name":"Bob","age":28},
  {"name":"Charlie","age":25}
]

Get the most out of this tool

Ready to sort your JSON array?

Free forever. No signup. Instant results.

Open JSON Sort Tool

Sorting JSON arrays effectively

Sorting a JSON array is a common data transformation needed before presenting data to users, comparing datasets, or preparing data for binary search. JSON arrays are ordered sequences, but the order they arrive in from an API or database query is often undefined or insertion-order — neither meaningful nor useful for display. Sorting gives the array a predictable order that matches user expectations or algorithmic requirements.

For arrays of primitive values (strings, numbers), sorting is straightforward. String arrays sort lexicographically by default — "banana" comes before "cherry" but after "apple". Numeric arrays need numeric sort, not lexicographic — "10" comes after "9" in lexicographic order but before in numeric order. This tool applies the correct sort type based on the array element types it detects, avoiding the common mistake of sorting numbers as strings.

For arrays of objects, you must specify a sort key — the field within each object to sort by. Sorting an array of user objects by "lastName" alphabetically, or sorting an array of transactions by "date" chronologically, or sorting an array of products by "price" numerically — these all require knowing which key to use and what type of comparison to apply. The tool supports specifying the sort key and sort direction (ascending/descending) for object arrays.

Stable sort is an important algorithmic property. A stable sort preserves the relative order of elements that compare as equal. If you sort a list of products by price, all products at the same price maintain their original relative order. Most modern JavaScript engines use a stable sort (TimSort or merge sort) since ECMAScript 2019 mandated stability. This tool uses JavaScript's Array.sort() which is stable in all modern environments.

Locale-aware string sorting is relevant for international data. Simple lexicographic sorting of "ü" (u-umlaut) places it after "z" because of its Unicode code point. Proper locale-aware sorting using the locale's collation rules places "ü" near "u" as a speaker of German would expect. JavaScript's String.localeCompare() and the Intl.Collator API handle this. For data that will be displayed to users in a specific locale, locale-aware sorting produces more natural results.

Sorting is frequently a precursor to other operations. Sorted arrays enable binary search instead of linear search — O(log n) instead of O(n). Sorted arrays make deduplication trivial — adjacent equal elements are easy to detect. Sorted arrays produce more readable diffs — comparing two sorted versions of the same dataset produces a minimal set of changes. Sorting before committing JSON data to version control dramatically improves the quality of Git diffs.

When developers use this tool

Preparing data for display API endpoints returning unsorted lists need client-side sorting before display. Sort the raw API response here to verify the correct sort order before implementing the sort logic in your application code.
Test data normalization When comparing expected versus actual JSON arrays in tests, sort both arrays by the same key first. This makes the comparison order-independent — useful when the API does not guarantee response element order.
Version control diff improvement Sort JSON arrays before committing to version control. When the array content changes between versions, a sorted array produces a clean diff showing only the actual additions and removals, not spurious order changes.
Data analysis preparation Before analyzing a JSON dataset — finding median values, building histograms, identifying top-N items — sort the array by the relevant field to make subsequent operations simpler to implement and verify.

Additional frequently asked questions

What happens when array elements have mixed types?

When a JSON array contains both strings and numbers, the sort behavior depends on comparison semantics. Numbers and strings cannot be meaningfully compared by value, so this tool groups numbers first (sorted numerically) then strings (sorted lexicographically) by default. Fully mixed-type arrays should be sorted programmatically with explicit comparison logic.

Can I sort a nested array (an array inside an object inside an array)?

The tool sorts the top-level array you provide. For nested arrays, extract the nested array first using the JSONPath evaluator or by manually isolating it, sort it here, then reassemble. Recursive sorting (sorting all arrays at all depths) is available via the API at api.jsonfmt.dev/sortby with a path parameter.

Is sorting a JSON array the same as sorting JSON object keys?

No. Sorting array elements reorders the elements in the array. Sorting object keys reorders the properties within an object. Both are useful but in different contexts. Array sorting is semantically meaningful — it changes which element is "first". Object key sorting is purely cosmetic — JSON semantics do not depend on key order, so it only affects readability and diff output.

Does this tool support multi-key sorting (sort by name, then by age)?

Multi-key sorting (secondary sort criteria) is available via the sort-by API endpoint. For browser-based use, sort by the primary key first, then use the custom sort comparison in your application code. The online tool currently supports single-key sort; complex multi-key sorting is better done programmatically.