JSON Key Sorter
FV-20Paste JSON and press Sort to put the keys of every object in alphabetical order. Numbers and strings are copied exactly as written. It runs in your browser.
Runs in your browser. Nothing is uploaded.
JSON
Sorted JSON
How to use it
- Paste your JSON into the input box, or open a .json file.
- Choose A to Z or Z to A, how keys are compared, and the indent.
- Optionally sort nested objects too, or sort arrays of numbers, strings or booleans.
- Press Sort and copy the result.
What gets sorted
Keys are sorted in every nested object unless you turn off the nested option, in which case only the top level is sorted. Arrays keep their order by default, because the order of items often matters. If you turn on array sorting, an array is sorted only when all of its items are numbers, all strings or all booleans. Arrays of objects and arrays with mixed items are left alone.
How keys are compared
The default compares keys by Unicode code point, so all capital letters come before lowercase letters and the result does not depend on a locale. Natural order puts item2 before item10, and the ignore-case option treats a and A as equal for ordering, but still tells e from é. Two keys that compare equal keep the order they had in the input. A key repeated inside one object is kept both times.
Exact numbers, new whitespace
The document is parsed without converting numbers, so 12345678901234567890 and 1.50 come out exactly as you typed them, and number arrays are sorted by their exact value. String escapes are kept too. What does change is the layout: the output is rewritten with the indent you pick, and the original spacing is not kept. Sorting does not change what the data means to a parser, since a JSON object has no defined key order.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Unexpected end of input at line 1, column 5 | The JSON stops before a value or bracket is finished, so there is nothing complete to sort. | Check the end of the text for a missing closing bracket, brace or quote. |
Expected a string key at line 1, column 2 | Inside an object the parser wanted a key in double quotes and found something else, such as a single quote or an unquoted name. | Put every key in double quotes and remove a comma before a closing brace. |
Questions people ask
How do I sort JSON keys alphabetically?
Paste the JSON and press Sort with A to Z selected. Every object's keys are reordered, including nested ones. Copy the result or download it as a .json file.
Why sort JSON keys at all?
A sorted file gives stable diffs in version control, makes two exports easy to compare, and makes a key easy to find in a long object. It is also useful before hashing or signing a document that must be written the same way every time.
Does sorting change my data?
Not for a JSON parser, because an object is a set of named values. Code that depends on key order, or an array you sorted, will see a different order. The values, numbers and strings are not changed.
Why does Zebra come before apple?
By default keys compare by character code, where capital letters come before lowercase ones. Choose the ignore-case option to order a and A together, or natural order to sort numbers inside names by value.
Are big numbers kept exact?
Yes. Numbers are copied as text, so 12345678901234567890 and 0.10 are written out unchanged. Number arrays are compared by exact value when array sorting is on, so large integers are not rounded.
Can I sort the items of an array?
Yes, when the array holds only numbers, only strings or only booleans, and the array option is on. Arrays of objects or mixed values keep their order, because there is no single obvious way to rank them.
About this tool
Reorders object keys and writes the document back with the indent you pick. Numbers and strings are copied exactly as written, so 12345678901234567890, 1.50 and escapes such as \u00e9 are not changed. By default keys are ordered by Unicode code point, so every capital letter comes before every lowercase letter and an emoji sorts after all other characters; the natural and ignore-case options use English collation instead. Arrays keep their order unless you turn on array sorting, and even then only an array whose items are all numbers, all strings or all booleans is sorted; arrays of objects or mixed items stay as they are, because their order often carries meaning. Number arrays compare by exact value. Equal keys keep their original order, and a key repeated in one object is kept both times. Whitespace and key order in the input are not preserved.