27

After needing a Diff tool for XML files? I now am looking for a diff tool for JSON data.

Same requirements:

  • Free
  • Tree-based, not line-based; i.e. if a section has moved to different place on the same level/in the same tree branch it should not report differences.
  • The order in JSON arrays is also irrelevant; swapped elements should be seen as 'no difference'.
  • All differences should be marked, preferably in a side-by-side view with indicators or lines connecting the sections that differ
  • An online version is fine

These two files should be reported as 'the same':

{
 "errormessage": "",
 "success": 1,
 "items": [
  {
   "id": 20100,
   "name": "AA3 met extra tekst2"
  },{
   "name": "Indirecte uren\\Ziekte",
   "id": 34
  }],
 "type": "ttgetlistresult"
}

and

{
 "errormessage": "",
 "items": [
  {
   "id": 34,
   "name": "Indirecte uren\\Ziekte"
  },{
   "id": 20100,
   "name": "AA3 met extra tekst2"
  }],
 "success": 1,
 "type": "ttgetlistresult"
}
  • 1
    As answered on the other question, I still believe Semantic Merge is your best bet. There ain't that many diff tools which cares for semantic and not only textual differences. – holroy Sep 22 '15 at 19:13
  • I have found at least three tools (e.g. this one) by searching for "json diff" on Google. Have you already tried them? – ComFreek Sep 22 '15 at 20:00
  • @ComFreek, I tried the tool you link to, and pasted in some json code which had been beautified by codebeautify.org/jsonviewer, and it says that the json is wrong... :( – holroy Sep 23 '15 at 10:49
  • 1
    @jans did you ever find a solution? If so, could you pelase accept an answer, or post your own? That would help otherrs – Mawg Apr 20 '17 at 8:16
9

My open source online json diff tool should do the trick: http://json-diff.com

http://json-diff.com

  • 6
    Nice. Is there a desktop version for it ? – Paul Praet Jan 20 '16 at 15:03
4

I recently found json-delta at https://pypi.python.org/pypi/json-delta/

You can install on your computer with command

pip install json-delta

To use it, just use the command

json_diff -u file1.json file2.json
  • JSON-delta is order sensitive when comparing arrays within the JSON, so while a very useful tool does not meet the OP's criteria. One note, if you are comparing JSON files that contain data expected to change (like timestamps) json-delta can be used to remove that data (via its patch capability) prior to doing your compare. – Chuck van der Linden Aug 28 '18 at 18:47
3

When researching for an answer to this question, besides a variant over using SemanticMerge as my suggested answer for "Diff tool for XML Files", I found another tool which claims to be context aware for a few programming languages: Compare++, which brags about the following:

Compared with other file comparison tools, the great process made in Compare++ is using language-aware structured comparison engine with two comparison modes ("Code-oriented" and "Text-oriented") to compare source files. Through completely understanding of code structures, you can get more precise code comparison results and abundant post-comparison features.
...
In order to help you review code structure changes, a dockable pane "Function View" is provided, in which all structure such as function, class or namespace changes(modified, removed or added) are listed.

...

Language-aware structured comparison for C/C++, Java, C#, Javascript, CSS, ...

  • Compare++ parses source files with built-in analysis for C/C++, C#, Java, php, html, Javascript, CSS3 and other languages, auto-extract the structured code tree and highlight syntax.
  • It can NOT ONLY compare the file content, but also display and report all function, classes, namespace changes in a side-by-side Function View.
  • In the Function View, you can customize filter mode to only display modified functions.

The program is not freeware (USD 29.95/user), but you can try it without a license for 30 days.

I'm not sure if it actually suggests that code is moved, or if that requires some manual labour, but it does claim in the functions view to be able to detect if it is modified, removed or added.

PS! On a side-note it does handle html, so possibly it can handle xml also?
PPS! Here is a tool in python to compare XML (which possibly could be changed into comparing json (if converted into an etree)). However this seems like it is written for equality checks, and doesn't provide that much visual feedback.

1

This might be useful:

It is a command line tool.

0

For online version that can also load files from disk, see this: http://www.jsondiff.com/

  • There is another answer that already suggest the very same tool. – Alejandro Oct 9 '18 at 12:42
  • 1
    @Alejandro No there is not; notice the hyphen – user416 Oct 9 '18 at 12:46
0

You can used online awesome tools like:- JSON Compare JSON Diff

  • 3
    Welcome to SoftwareRecs, but this is a low quality answer. 1. Your links are reversed 2. JSON Diff is already mentioned elsewhere 3. This is a link-only answer and risks getting deleted softwarerecs.meta.stackexchange.com/questions/624/… Please edit the answer – user416 Feb 12 at 10:01
-3

Just use diff. Like in

diff --unified file1.json file2.json

(source; details on --unified)

  • 2
    IMHO this is much line-based and order matters, which the OP does both not want. Therefore, it does not answer the question. – Thomas Weller Jun 7 '16 at 22:01
  • @ThomasWeller you're right. The two files from the question description are not considered equal. I may delete it, though this solution still might help someone (as it helped me). – Dennis Golomazov Jun 7 '16 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy