Skip to content
CALZYRA— TOOLS THAT EMPOWER —
FinanceInvestmentsHealthMathBlog
CALZYRA— TOOLS THAT EMPOWER —

Practical calculators and online tools, made to be simple and useful.

Popular Categories

  • Finance
  • Health & Fitness
  • Mathematics
  • Physics
  • Construction
  • Conversion

Finance Tools

  • Loan Calculators
  • Investment Calculators
  • Compound Interest
  • SIP Calculator
  • ROI Calculator
  • CAGR Calculator

Top Calculators

  • Mortgage Calculator
  • BMI Calculator
  • Percentage Calculator
  • Calorie Calculator
  • Tip Calculator

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 Calzyra. All rights reserved.

Free tools for everyday calculations, learning, and practical work.
HomeDeveloper ToolsJSON ToolsJSON Sorter

JSON Sorter Online – Sort JSON Keys Alphabetically

Sort JSON online, free and in your browser. Paste a document, choose key name or key value and a direction, and the sorter reorders it - keys stay attached to their own values, nested objects are handled too, and arrays only move when you ask for value sorting.

Useful when a config file, an API payload or a fixture has its properties scattered in an order nobody chose deliberately, and you want it consistent before you read it, diff it or commit it.

Ctrl+Enter to sort
Sorting options

Key name orders the properties of every object A to Z. Key value orders entries by what they hold instead.

Ascending reads A to Z; descending reverses it. Values keep their own types either way.

Only used when sorting by key value, where it picks the property that decides the order of a list.

5 objects ordered by key name (A to Z). 1 array kept their original order.
json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "name": "Alice",
  "email": "alice@example.com",
  "age": 28,
  "city": "Lahore",
  "active": true,
  "address": {
    "zip": "54000",
    "country": "Pakistan",
    "city": "Lahore"
  },
  "users": [
    { "name": "John", "age": 30 },
    { "name": "Sarah", "age": 25 },
    { "name": "Miguel", "age": 35 }
  ]
}
17 lines317 chars42 wordsjson

Paste your JSON here. It has to be valid before anything can be sorted, and your document never leaves this browser tab.

2-space indent
json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "active": true,
  "address": {
    "city": "Lahore",
    "country": "Pakistan",
    "zip": "54000"
  },
  "age": 28,
  "city": "Lahore",
  "email": "alice@example.com",
  "name": "Alice",
  "users": [
    {
      "age": 30,
      "name": "John"
    },
    {
      "age": 25,
      "name": "Sarah"
    },
    {
      "age": 35,
      "name": "Miguel"
    }
  ]
}
26 lines365 chars42 wordsjsonRead Only

Related JSON tools

JSON Formatter

Format and beautify JSON into readable JSON

JSON Minifier – Minify JSON Online

Minify JSON into a single line

JSON Diff Tool

Compare and diff two JSON objects

JSON Validator – Validate JSON Online

Validate JSON syntax and find errors

JSON Beautifier

Beautify JSON for easy reading

JSON Tree Viewer

View JSON as an expandable tree

JSON to CSV Converter

Convert JSON arrays to CSV rows and columns

JSON to YAML Converter

Convert JSON to indented YAML

What Is a JSON Sorter?

A JSON sorter takes a document and writes it back in a chosen order: properties from A to Z, the same properties from Z to A, or entries ordered by the values they hold. It is the tool you reach for when the JSON is correct but awkward - keys in whatever order the server happened to emit them, a file that never matches the copy sitting next to it, a payload that is hard to scan because nothing is where you expect it.

What changes is sequence, and only sequence. Every key keeps its own value, every value keeps its type and its content, and the result still parses to the same data. Sorting {"name": "John", "age": 30} into {"age": 30, "name": "John"} is a rewrite of order, not of information.

There is an important technical detail behind that. The JSON data model describes object members as an unordered set of name/value pairs, so no conforming parser attaches meaning to the position of a property - {"a": 1, "b": 2} and {"b": 2, "a": 1} are the same document. Sorting is therefore not something you do to make JSON work. It is something you do to make it readable, stable and comparable - which is exactly when it earns its keep.

How to Sort JSON Online

Five steps, and none of them involve uploading anything: the parsing and the sorting both happen in this browser tab.

  1. 1. Paste your JSON

    Put the document in the JSON to sort panel on the left. The example above is already loaded, so you can replace it with your own whenever you are ready.

  2. 2. Choose how to sort

    Sort by picks between key name and key value, Order picks ascending or descending, and Key name - which is only enabled for value sorting - names the property that decides the order of a list of objects.

  3. 3. Run the sorter

    Press Sort JSON, or hit Ctrl+Enter from anywhere on the page. The panel also re-sorts a quarter of a second after you stop typing, so the result keeps up with your edits.

  4. 4. Review the result

    The sorted document appears on the right, and the status line underneath the options says how many objects were ordered and what happened to the arrays.

  5. 5. Copy the result

    Press Copy result to move the sorted JSON to your clipboard, ready to paste into a file, a pull request or a bug report.

The status line between the options and the editors is worth watching: it reports how many objects were ordered and what happened to the arrays, or it points at the line where your JSON stopped parsing.

How JSON Sorting Works

The input is parsed first, so nothing is ever reordered by text manipulation. The sorter then walks the parsed tree, rewrites each object from the ordered list of its entries, and writes the result back out with a two-space indent. Because each key travels together with its value, there is no point in the algorithm where a key could end up holding somebody else’s value.

Key name ordering compares property names character by character, the same way JavaScript’s own sort() does. One consequence worth expecting: the comparison is on characters, not on meaning, so digits sort before letters and "10" comes before "2" because 1 is alphabetically earlier than 2. That is ordinary lexicographic behaviour and it is what every other alphabetical sort of string keys will give you too.

Value ordering has to cope with mixed types, so it uses a stable, predictable ranking: numbers first (compared numerically, so 9 lands before 10), then strings, then booleans, then null, then objects and arrays. Two values of the same type are compared naturally, and values of different types never jump around between runs. Ascending follows that ranking exactly; descending reverses it, so arrays and objects come first and numbers come last.

One honest caveat about the output: it is re-serialized, so the text can be normalised even though the data is not changed. A number written as 1.0 comes back as 1, and an escape sequence may be written in its shortest form. Both parse to the identical value. If you need the original bytes preserved exactly, you want a formatter or minifier that copies strings through untouched rather than a sorter.

Sort JSON Keys Alphabetically

Alphabetical key sorting is the default mode, and it is the most common reason people look for a JSON key sorter at all. The document below has three properties in no particular order:

Before
{
  "zebra": 1,
  "apple": 2,
  "mango": 3
}
After - ascending (A to Z)
{
  "apple": 2,
  "mango": 3,
  "zebra": 1
}

The keys moved; the values 1, 2 and 3 stayed with the key they belonged to. Switching the Order control to descending reverses the sequence:

After - descending (Z to A)
{
  "zebra": 1,
  "mango": 3,
  "apple": 2
}

Sort JSON by Key or Value

Two things decide the output: what the order is based on, and which direction it runs in. Both are choices in the options bar, and both take effect immediately.

Sort by key name

Orders the properties of every object alphabetically, at every level of the document. This is the safe default: array items are never moved, so a list stays in the order someone deliberately put it in while the objects inside it get their keys straightened out.

Sort by key value

Orders entries by what they hold instead of what they are called. Object properties are arranged by their values, a list of plain values is arranged by those values, and a list of objects is arranged by the property named in the Key name field. Leave that field empty and the first property of the first item names the property for the whole list - handy when every object in it lists its properties the same way.

Here the list of users is ordered by age with Order set to descending, so the oldest person comes first:

Input
[
  { "name": "Sarah", "age": 25 },
  { "name": "John", "age": 30 },
  { "name": "Miguel", "age": 35 }
]
After - by "age", descending
[
  {
    "name": "Miguel",
    "age": 35
  },
  {
    "name": "John",
    "age": 30
  },
  {
    "name": "Sarah",
    "age": 25
  }
]

Ascending and descending

Ascending means A to Z for keys and smallest first for values; descending flips both - Z to A, largest first, and for mixed types the ranking above runs backwards. The direction applies everywhere in the document at once, so nested objects and arrays follow the same rule as the top level. If the result comes back with a note saying the document was already in that order, nothing needed moving - the input was sorted to begin with.

JSON Sorting Example

A small profile object, before and after sorting its keys alphabetically:

Before
{
  "name": "Alice",
  "email": "alice@example.com",
  "age": 28,
  "city": "Lahore"
}
After - key name, ascending
{
  "age": 28,
  "city": "Lahore",
  "email": "alice@example.com",
  "name": "Alice"
}
  • The order of the four properties changed - email and city now sit before name.
  • Each value stayed with its own key: age is still 28 and the city is still Lahore.
  • Nothing was renamed, converted or dropped. The document says exactly what it said before, in a more predictable shape.

Sorting Keys vs Sorting Array Values

This is the distinction that matters most, and it is easy to get wrong. Object keys are a set of names, so moving them is a cosmetic change. Array items are positions, so moving them is a change to the data.

Take a list of users. In key sorting mode, the keys inside those user objects are alphabetised while John stays before Sarah, because the array itself was not part of the request:

Input
{
  "users": [
    { "name": "John", "age": 30 },
    { "name": "Sarah", "age": 25 }
  ],
  "total": 2
}
After - key name, ascending
{
  "total": 2,
  "users": [
    {
      "age": 30,
      "name": "John"
    },
    {
      "age": 25,
      "name": "Sarah"
    }
  ]
}

Value sorting is the mode that does reorder a list, and only because you asked it to. Plain values are ordered directly; a list of objects is ordered by the named property; a list whose items are themselves arrays, or a mix of shapes with no single value per item, keeps its position because there is nothing sensible to order it by.

Nested JSON

Sorting is recursive. The walk does not stop at the top level: every object in the tree gets the same treatment, whether it sits directly under the root, inside another object, or inside an array.

Before
{
  "user": {
    "zip": "54000",
    "name": "Ali",
    "address": {
      "country": "Pakistan",
      "city": "Lahore"
    }
  }
}
After - key name, ascending
{
  "user": {
    "address": {
      "city": "Lahore",
      "country": "Pakistan"
    },
    "name": "Ali",
    "zip": "54000"
  }
}

Both levels were reordered: address now comes before name and zip, and inside it the city now comes before the country. The string values themselves were left exactly as they were - sorting keys never edits what a value says.

When Should You Sort JSON?

Nobody sorts JSON for the parser’s benefit. These are the situations where it genuinely helps:

  • Cleaner diffs

    When two generated JSON files hold the same properties in a different order, Git reports every line as changed even though almost nothing moved. Sorting both files first collapses that noise, and the diff that is left is the diff you actually care about.

  • Easier comparison

    Two responses from the same endpoint, a fixture and a live payload, a config before and after a migration - all of them compare cleanly once both sides list their keys in the same order. The JSON Diff then highlights real differences instead of ordering differences.

  • Configuration files

    A large settings object is easier to scan when related keys sit together and the alphabet decides where a new key goes. Reviewers stop hunting through the file, and a missing key stands out because its neighbours are where they should be.

  • Debugging API responses

    If the same request sometimes returns keys in one order and sometimes in another, eyeballing two payloads is miserable. Sorting both removes the ordering noise so the value that actually differs is the one that jumps out.

  • Snapshot testing

    Serializers and databases do not promise to emit properties in a stable order, so snapshots can fail for reasons that have nothing to do with behaviour. Sorting keys before writing the snapshot keeps the comparison about the data.

There are also times not to sort. If the order of an array carries meaning - a queue, a ranked list, coordinates, a log of events - leave it alone, or use value sorting deliberately rather than by accident. And if all you need is for a single-line response to become readable, the JSON Formatter does that without touching the order of anything.

When the JSON Is Invalid

Sorting needs a document it can parse. If the input is malformed, the sorter stops, produces no output and reports the problem with its line, column and character position - along with the offending line and a caret under the exact break - so you can go straight to the mistake instead of hunting for it.

The problems that come up most often are small ones:

  • A missing comma between two entries
  • An unquoted property name, or one wrapped in single quotes
  • A trailing comma before a closing brace or bracket
  • Braces and brackets that do not balance
  • A comment or a literal newline inside a string - JSON allows neither

An empty panel is handled separately: the sort button stays disabled and the status line asks for input rather than pretending an empty result is a sorted one. When the document is valid but you want a second opinion on it, the JSON Validator reports the same class of problems in more detail.

Frequently Asked Questions

What does a JSON sorter do?▾

It rewrites a JSON document so its entries appear in the order you asked for: object properties from A to Z or Z to A, or entries ordered by the values they hold. Keys move as a pair with their own value, so the sorted document still parses to exactly the same data as the input - only the sequence on the page is different.

Can I sort JSON keys alphabetically?▾

Yes - that is the default mode of this tool. Key name sorting compares property names character by character and reorders them A to Z, and switching Order to descending reverses that to Z to A. The comparison runs on every object in the document, including objects nested several levels deep and objects sitting inside arrays.

Does sorting JSON change the data?▾

No. Sorting only changes the order in which entries are written. Values keep their types and their content, every key stays attached to its own value, and arrays keep their item order unless you explicitly choose value sorting. The output is re-serialized with a two-space indent, so the exact text can differ in harmless ways - a number written as 1.0 can come back as 1 - but the document means the same thing to any parser.

Does JSON key order matter?▾

In the JSON data model, no: object members are an unordered set of name/value pairs, so two objects with the same members are the same data regardless of the order they are written in. In practice order still matters to humans and to tooling - diffs, snapshots, hash comparisons and side-by-side reviews all get easier when every copy lists its keys the same way. That is what a sorter is for.

Can nested JSON objects be sorted?▾

Yes. The sorter walks the whole tree rather than only the top level, so an object nested inside another object, inside an array, or several layers down has its keys ordered too. The example in the Nested JSON section shows the result of sorting a document with two levels of nesting.

Are JSON arrays sorted?▾

Not when you sort by key name. The position of an array item is part of its meaning, so ["John", "Sarah"] and ["Sarah", "John"] are different data, and reordering them silently would be a data change. Value sorting is the mode that may reorder a list: primitive items are ordered directly, and a list of objects is ordered by the property named in the Key name field - or by the first property of the first item in that list if the field is left empty.

Can I sort JSON in ascending or descending order?▾

Yes. The Order control switches between ascending (A to Z for keys, smallest first for values) and descending (Z to A, largest first). Changing it re-runs the sort immediately, so you do not have to paste the document again.

Why should I sort JSON before comparing two files?▾

Because an unsorted comparison mostly reports ordering. If two files contain the same data but list their keys differently, a plain text diff lights up even though nothing meaningful changed. Sorting both files first gives them a consistent structure, and what remains in the diff is the actual difference between them.

What happens if my JSON is invalid?▾

No output is produced. The document is validated before anything is sorted, and the panel reports the problem with its line, column and character position along with the offending line and a caret under the break - the usual causes are a missing comma, an unquoted key, a trailing comma or mismatched braces. Fix the syntax and the sorted result appears without any further action.

After the sort

Sorted JSON is usually a step, not the destination. Copy it into the comparison you were setting up - JSON Diff will then show real differences instead of ordering noise - or inspect the structure in the JSON Tree Viewer when you want to see where a value lives before deciding what to do with it. When the file needs to travel, the JSON Minifier strips the indentation back out without disturbing the key order you just fixed.

JSON Tools

JSON FormatterJSON Validator – Validate JSON OnlineJSON Minifier – Minify JSON OnlineJSON BeautifierJSON Tree ViewerJSON to CSV ConverterJSON to XML ConverterJSON to YAML ConverterJSON Diff ToolJSON Merge ToolJSON FlattenerJSON UnflattenerJSON Schema ValidatorJSON Path TesterJSON SorterJSON Pretty PrintJSON Escape ToolJSON Unescape ToolJSON to TypeScript InterfaceJSON to TypeScript Interface GeneratorJSON Query ToolJSON Compare ToolJSON Statistics CalculatorJSON Size CalculatorJSON Optimizer

About this sorter

  • Sorts object keys by name or by value, ascending or descending.
  • Walks the whole tree, so nested objects are ordered too - not just the top level.
  • Never reorders array items in key mode; value mode reorders them only when you ask it to.
  • Keys and values travel together, so no value can end up attached to the wrong key.
  • Reports invalid JSON with its line and column, and produces no output in that case.
  • Runs entirely in your browser – no uploads.