{
"color": "red",
"count": 2
}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.
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.
{"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.
Alphabetical keys turn a diff into a value comparison, which is what you want when two writers disagree only about order.
Keys move. Values stay attached to their keys. Arrays keep item order. 2 stays 2 and red stays red.
A unified diff compares text. count-then-color against color-then-count looks like every line changed. Alphabetical keys on both sides leave a hunk only where a value differs. JSON diff does this sort itself.
Yes. Each object is sorted on its own keys, at every depth.
Keys are sorted as strings, so A to Z with digits ordered by their character code. Color and color are different keys.
It is pretty-printed at two spaces. Run the minifier afterward if you need the sorted document on one line.