Skip to content
All guides

A little guidance

How to sort JSON keys alphabetically

Press the A–Z button in the Preview toolbar to order the keys of every object in your JSON, which makes two files much easier to compare.

Advertisements

Sort JSON keys

Sort every key in the orders A–Z

We pressed the Sort keys A–Z button in the Preview toolbar. Each order now lists customer, id, items, notes, paid, shipped; the orders array kept its order.

The orders JSON in the tree with the Sort keys A–Z button highlighted in the toolbar, keys sorted at the top level and inside each order.
Keys are sorted at every level; arrays keep their order. View full size
LevelBeforeAfter
Topstore, currency, updated, orderscurrency, orders, store, updated
Orderid, customer, items, paid, shipped, notescustomer, id, items, notes, paid, shipped
ArraysOrders 1042, 1043, 1044Same order

Undo puts the original key order back.

Repeat this example

  1. Open the JSON.
  2. Press the A–Z button in the Preview toolbar.
  3. Copy or save it.

Check the result

At the top level, currency now comes before orders, store and updated.

A common mistake

Expecting arrays to be sorted too: array order is part of the data and stays as it is.

Open JSON Prettifier

Sources and credits

Sample JSON made for these guides. The bookshop orders, names and emails are invented. Every screenshot shows the real tool working on that JSON.

Open the JSON

Paste it or open a .json file.

Press Sort keys A–Z

The A–Z button with a down arrow is in the toolbar at the top of the Preview. Keys in every object, at every level, are sorted alphabetically at once, and the button stays highlighted while sorting is on. Arrays keep their order, because the order of items matters.

Use it to compare files

Sorting two versions of a config or API response the same way puts matching keys on the same lines. To see the differences directly, choose Compare at the top of the left panel, which ignores key order by default.

Get the original order back

Press Undo (or Ctrl/Cmd+Z) right after sorting and the keys go back to their original order and the button turns off. Pressing the button again only stops sorting new changes.

  • JSON Prettifier

    How to compare two JSON files and see the differences

    Put two JSON documents side by side in JSON Prettifier: every changed, added and removed value is marked and listed, even when the keys are in a different order.

Advertisements