Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste JSON into Source text.
  2. There is no option for sort direction or for which level to touch. Every object is sorted.
  3. Read the pretty-printed result. Array order matches the source.
  4. Copy it, or pass both sorted texts to a diff if you are comparing outside JSON diff.

What is Sort JSON keys?

Two JSON files can hold the same data and still produce a noisy diff because one writer emitted count first and the other emitted color first. Sort JSON keys rewrites every object so its keys are in alphabetical order, and it does the same inside nested objects. Arrays stay in their existing order, because position in an array is data. The result is pretty-printed with two spaces.

Read more

After both sides of a comparison have been sorted, a diff that still shows a line is a real value change. JSON diff sorts for you before it compares, so key order alone produces a patch with no added or removed lines. Use this page when you need the sorted document itself, to store or to send, not only the comparison.

Use cases

  • A reviewer sorts a generated config before committing so the next generation diffs by value.
  • Two services emit the same object with different key order. Sorting both makes the files match.
  • A snapshot test stores the sorted form so a new key lands in a predictable place.
  • Someone preparing a JSON diff sorts a file by hand to see the stable shape.
  • A nested settings object is alphabetized at every level, not only at the root.

count and color, alphabetized

{"count":2,"color":"red"}. The sample paste {"color":"red","count":2} is already in alphabetical order.

{ "color": "red", "count": 2 } color comes before count. The sample paste returns that same text because it was already sorted.

Why use Oddsock

Alphabetical keys turn a diff into a value comparison, which is what you want when two writers disagree only about order.

Related tools

Using this tool

Keys move. Values stay attached to their keys. Arrays keep item order. 2 stays 2 and red stays red.