Updated · Built and checked by the PlinzoTools team, formulas tested against published sources
Sort a JSON array of objects by a specific key.
Sorted array will appear here.
This tool sorts a JSON array of objects by a specific key's value, in ascending or descending order -- handling both numeric and text values automatically.
Paste your JSON array, enter the key to sort by, and choose ascending or descending. The sorted JSON array appears instantly.
The tool makes a single decision for the whole array before sorting. It checks every element: if every element is an object and the value under your chosen key can be read as a number, the sort is numeric. If even one element fails that test, the whole array falls back to a text sort using a locale-aware string comparison. This all-or-nothing rule is the most important thing to understand, because one odd record can change how every other record is ordered.
In the numeric case, values are compared by their numeric value, so 2 comes before 10 and negative numbers and decimals order correctly. Numbers stored as strings, such as "42", also count as numeric. In the text case, values are converted to strings and compared with a locale-aware comparison, which is alphabetical and does not distinguish sharply between upper and lower case the way a raw character-code sort would. A missing or null value in text mode is treated as an empty string and therefore sorts to the front in ascending order.
Use this made-up array of products: Lamp with price 30, Mug with price 8, Desk with price 120. Sorting by price ascending gives Mug, Lamp, Desk. Descending reverses this to Desk, Lamp, Mug. Now add a fourth product, Sticker, with no price key at all. The check for that element reads the missing value as not a number, so the whole array switches to text mode. The prices then compare as strings, and 120 sorts before 30 and 8 because the character 1 comes before 3 and 8. This surprising result is a direct consequence of the all-or-nothing rule, so if you see numbers in a strange order, look for records with a missing, empty, or non-numeric value for that key.
Sorting is handy when preparing test fixtures, inspecting API responses for the largest or newest entries, or tidying a configuration file whose entries should be alphabetical. Because the operation runs entirely in your browser, you can reorder data without installing tooling, and the output remains valid JSON that can be pasted directly back into code or a config file.
Yes -- if the key's values are numeric, they're sorted numerically (so 2 comes before 10); text values sort alphabetically.
At least one object probably has a missing key or a value that cannot be read as a number. The tool sorts numerically only when every element passes that test; otherwise it sorts all values as text.
Yes. Records with equal sort values remain in the same relative order as in your input.
Not in a single step. Sort by the secondary key first, then run the result again with the primary key. Stability keeps the earlier ordering among ties.
No. It works on a copy in your browser and shows the sorted array as output. Your pasted text is not modified or uploaded.