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 ToolSorted JSON in four steps
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
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.
[
{"name":"Charlie","age":25},
{"name":"Alice","age":30},
{"name":"Bob","age":28}
]
[
{"name":"Alice","age":30},
{"name":"Bob","age":28},
{"name":"Charlie","age":25}
]
Get the most out of this tool
- Sort arrays by a date or timestamp field to quickly find the most recent or oldest entries.
- Use descending sort on numeric fields like "score" or "count" to surface the highest-value items first.
- Combine array sorting with the filter tool to extract and rank a subset of records from large datasets.
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
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.