Find and return JSON differences using newtonsoft in C#?

user167908 picture user167908 · Jul 22, 2014 · Viewed 51.9k times · Source

I'd like to get a list of the JSON parts that don't match when doing a comparison using Newtonsoft.

I have this code that compares:

JObject xpctJSON = JObject.Parse(expectedJSON);
JObject actJSON = JObject.Parse(actualJSON);

bool res = JToken.DeepEquals(xpctJSON, actJSON);

But can't find anything that returns the diff's.

Answer

Achilles picture Achilles · Nov 14, 2017

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);