40

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"
}
8
  • 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
    Commented Sep 22, 2015 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
    Commented Sep 22, 2015 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
    Commented Sep 23, 2015 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
    Commented Apr 20, 2017 at 8:16
  • None of the answers satisfy the main requirement ("swapped elements should be seen as 'no difference'"). The asker is not active anymore. The title does not mention that very special requirement, which is probably why all answers ignored it. Should we just remove that requirement?
    – Nicolas Raoul
    Commented Jan 7, 2021 at 6:53

7 Answers 7

11

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

http://json-diff.com

4
  • 8
    Nice. Is there a desktop version for it ?
    – Paul Praet
    Commented Jan 20, 2016 at 15:03
  • 3
    The order in JSON arrays is also irrelevant; swapped elements should be seen as 'no difference'.. How to do this? I see the diff is order sensitive. Is there an option? Commented Jan 3, 2020 at 17:35
  • Sort them on something before comparing...
    – ntg
    Commented Sep 26, 2021 at 10:16
  • That does NOT solve the OPs problem. Commented May 17, 2022 at 11:50
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
1
  • 2
    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. Commented Aug 28, 2018 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.

2

This might be useful:

It is a command line tool.

1

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

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

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

2
  • 4
    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
    Commented Feb 12, 2019 at 10:01
  • @user416 So what's the problem with just giving links? Commented Jan 23, 2023 at 14:42
-4

Just use diff. Like in

diff --unified file1.json file2.json

(source; details on --unified)

2
  • 2
    IMHO this is much line-based and order matters, which the OP does both not want. Therefore, it does not answer the question. Commented Jun 7, 2016 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). Commented Jun 7, 2016 at 22:06