🌐
JSON Diff
jsondiff.com
JSON Diff - The semantic JSON compare tool
Validate, format, and compare two JSON documents. See the differences between the objects instead of just the new lines and mixed up properties.
🌐
Reddit
reddit.com › r/cpp › c++ json library comparison
r/cpp on Reddit: C++ JSON library comparison
August 29, 2024 -

Update an old comparison library that compares Conformance/Performance of known C++ JSON libraries and automated the builds to publish the results (so everyhting is build on github as the comparison hosts).

https://github.com/Loki-Astari/JsonBenchmark

Conformance mac linux
Performance mac linux

🌐
JSON for Modern C++
json.nlohmann.me › api › basic_json › diff
diff - JSON for Modern C++
#include <iostream> #include <iomanip> #include <nlohmann/json.hpp> using json = nlohmann::json; using namespace nlohmann::literals; int main() { // the source document json source = R"( { "baz": "qux", "foo": "bar" } )"_json; // the target document json target = R"( { "baz": "boo", "hello": [ "world" ] } )"_json; // create the patch json patch = json::diff(source, target); // roundtrip json patched_source = source.patch(patch); // output patch and roundtrip result std::cout << std::setw(4) << patch << "\n\n" << std::setw(4) << patched_source << std::endl; }
🌐
Stack Overflow
stackoverflow.com › questions › 49937907 › json-comparison-in-c
json Comparison in c++ - Stack Overflow
I didn't compile code, so there might be some errors/typos. ... Yes using jsoncpp I am getting errors , but the logic looks good and hopefully it will work(just want to compare input1 and input2 based on schema or reference json , was able to do it but was unable to get the keys those are nested that was the bug the logic will fail if some deeper array keys are missing in referce json but are not required it will say the input1 and input2 are not equal but according to the logic it should be) .
🌐
npm
npmjs.com › package › json-diff
json-diff - npm
Anyone who gets a significant pull request merged gets commit access to the repository. ... % json-diff --help Usage: json-diff [-vCjfonskKp] first.json second.json Arguments: <first.json> Old file <second.json> New file General options: -v, --verbose Output progress info -C, --[no-]color Colored output -j, --raw-json Display raw JSON encoding of the diff -f, --full Include the equal sections of the document, not just the deltas --max-elisions COUNT Max number of ...s to show in a row in "deltas" mode (before collapsing them) -o, --output-keys KEYS Always print this comma separated keys, with their value, if they are part of an object with any diff -x, --exclude-keys KEYS Exclude these comma separated keys from comparison on both files -n, --output-new-only Output only the updated and new key/value pairs (without marking them as such).
      » npm install json-diff
    
Published   May 15, 2023
Version   1.0.6
Author   Andrey Tarantsov
🌐
Js
json-diff-kit.js.org
JSON Diff Kit Playground
We cannot provide a description for this page right now
🌐
JSON for Modern C++
json.nlohmann.me › features › json_patch
JSON Patch and Diff - JSON for Modern C++
#include <iostream> #include <iomanip> #include <nlohmann/json.hpp> using json = nlohmann::json; using namespace nlohmann::literals; int main() { // the source document json source = R"( { "baz": "qux", "foo": "bar" } )"_json; // the target document json target = R"( { "baz": "boo", "hello": [ "world" ] } )"_json; // create the patch json patch = json::diff(source, target); // roundtrip json patched_source = source.patch(patch); // output patch and roundtrip result std::cout << std::setw(4) << patch << "\n\n" << std::setw(4) << patched_source << std::endl; }
🌐
Thousandeyes
blog.thousandeyes.com › efficiency-comparison-c-json-libraries
Efficiency Comparison of C++ JSON Libraries | ThousandEyes
Compares the parsing and serialization efficiency of three different C++ JSON libraries, JsonCpp, Casablanca, and JSON Spirit.
Top answer
1 of 9
48

Just to help future queries. There's a nice json diff tool I came across. It works flawlessly for diff/patch of json structures:

jsondiffpatch.net There's also a nuget package for it.

usage is straightforward.

var jdp = new JsonDiffPatch();
JToken diffResult = jdp.Diff(leftJson, rightJson);
2 of 9
27

There is my solution based on the ideas from the previous answers:

public static JObject FindDiff(this JToken Current, JToken Model)
{
    var diff = new JObject();
    if (JToken.DeepEquals(Current, Model)) return diff;

    switch(Current.Type)
    {
        case JTokenType.Object:
            {
                var current = Current as JObject;
                var model = Model as JObject;
                var addedKeys = current.Properties().Select(c => c.Name).Except(model.Properties().Select(c => c.Name));
                var removedKeys = model.Properties().Select(c => c.Name).Except(current.Properties().Select(c => c.Name));
                var unchangedKeys = current.Properties().Where(c => JToken.DeepEquals(c.Value, Model[c.Name])).Select(c => c.Name);
                foreach (var k in addedKeys)
                {
                    diff[k] = new JObject
                    {
                        ["+"] = Current[k]
                    };
                }
                foreach (var k in removedKeys)
                {
                    diff[k] = new JObject
                    {
                        ["-"] = Model[k]
                    };
                }
                var potentiallyModifiedKeys = current.Properties().Select(c => c.Name).Except(addedKeys).Except(unchangedKeys);
                foreach (var k in potentiallyModifiedKeys)
                {
                    var foundDiff = FindDiff(current[k], model[k]);
                    if(foundDiff.HasValues) diff[k] = foundDiff;
                }
            }
            break;
        case JTokenType.Array:
            {
                var current = Current as JArray;
                var model = Model as JArray;
                var plus = new JArray(current.Except(model, new JTokenEqualityComparer()));
                var minus = new JArray(model.Except(current, new JTokenEqualityComparer()));
                if (plus.HasValues) diff["+"] = plus;
                if (minus.HasValues) diff["-"] = minus;
            }
            break;
        default:
            diff["+"] = Current;
            diff["-"] = Model;
            break;
    }

    return diff;
}
Find elsewhere
🌐
GitHub
github.com › bergant › jsondiff
GitHub - bergant/jsondiff: Compare R Objects as JSONs
Diffing R objects (like lists and dataframes) is also supported by automatic conversion to JSON. It is implemented as an R interface to jsondiffpatch, powered by htmlwidgets framework. ... x <- list( name = "Pluto", orbital_speed_kms = 4.7, category = "planet", composition = c("methane", "nitrogen") ) y <- list( name = "Pluto", category = "dwarf planet", orbital_speed_kms = 4.7, composition = c("nitrogen", "methane", "carbon monoxide") ) library(jsondiff) jsondiff(x, y)
Author   bergant
🌐
JSON Compare
jsoncompare.org
JSON Compare - Best JSON Diff Tools
Online json compare tool is used to find json diff online. Input json code, json file compare, compare 2 json files, directly json url to compare & beautify.
🌐
GitHub
github.com › wbish › jsondiffpatch.net
GitHub - wbish/jsondiffpatch.net: JSON object diffs and reversible patching (jsondiffpatch compatible) · GitHub
JSON object diffs and reversible patching (jsondiffpatch compatible) Install from jsondiffpatch.net nuget website, or run the following command: ... The library has support for the following 3 operations: Diff, Patch and Unpatch.
Author   wbish
🌐
GitHub
github.com › josephburnett › jd
GitHub - josephburnett/jd: JSON diff and patch · GitHub
Prints the diff of FILE1 and FILE2 to STDOUT. When FILE2 is omitted the second input is read from STDIN. When patching (-p) FILE1 is a diff. Options: -color Print color diff. -p Apply patch FILE1 to FILE2 or STDIN.
Author   josephburnett
🌐
NuGet
nuget.org › packages › JsonDiffer
NuGet Gallery | JsonDiffer 1.0.1
As mentioned this new object model groups changes in removed, changed and added properties in the result object recursively. Given the same json samples: var j1 = JToken.Parse(Read(json1)); var j2 = JToken.Parse(Read(json2)); var diff = JsonDifferentiator.Differentiate(j1,j2, outputMode = OutputMode.Detailed);
🌐
JSON Diff
json-diff.com
JSON Diff - Compare and Find Differences in JSON Files Online
JSON Diff is a free and open-source tool to compare two JSON objects and find differences. Visualize changes in JSON files, easy and fast.
🌐
SourceForge
sourceforge.net › projects › json-diff.mirror
JSON-Diff download | SourceForge.net
Download JSON-Diff for free. Structural diff for JSON files. json-diff is a command-line tool (and library) that computes differences between two JSON documents in a user-friendly manner.
🌐
JSONLint
jsonlint.com › json-diff
JSON Diff - Compare Two JSON Objects | JSONLint | JSONLint
Usually it's whitespace or key ordering. Try clicking "Format" on both sides first. If they still differ, look for subtle type differences like "1" (string) vs 1 (number). Not directly in this tool, but you can use the JSON Validator with the ?url= parameter to fetch JSON, then copy it here.