Textually diffing JSON

Posted by Richard Levasseur on Stack Overflow See other posts from Stack Overflow or by Richard Levasseur
Published on 2011-01-04T23:19:41Z Indexed on 2011/01/08 4:54 UTC
Read the original article Hit count: 359

Filed under:
|
|
|

As part of my release processes, I have to compare some JSON configuration data used by my application. As a first attempt, I just pretty-printed the JSON and diff'ed them (using kdiff3 or just diff).

As that data has grown, however, kdiff3 confuses different parts in the output, making additions look like giant modifies, odd deletions, etc. It makes it really hard to figure out what is different. I've tried other diff tools, too (meld, kompare, diff, a few others), but they all have the same problem.

Despite my best efforts, I can't seem to format the JSON in a way that the diff tools can understand.

Example data:

[
  {
    "name": "date",
    "type": "date",
    "nullable": true,
    "state": "enabled"
  },
  {
    "name": "owner",
    "type": "string",
    "nullable": false,
    "state": "enabled",
  }
  ...lots more...
]

The above probably wouldn't cause the problem (the problem occurs when there begin to be hundreds of lines), but thats the gist of what is being compared.

Thats just a sample; the full objects are 4-5 attributes, and some attributes have 4-5 attributes in them. The attribute names are pretty uniform, but their values pretty varied.

In general, it seems like all the diff tools confuse the closing "}" with the next objects closing "}". I can't seem to break them of this habit.

I've tried adding whitespace, changing indentation, and adding some "BEGIN" and "END" strings before and after the respective objects, but the tool still get confused.

© Stack Overflow or respective owner

Related posts about python

Related posts about JSON