'How can you identify indiviudal items from a Json Diff back in the original Json that you compared?
(Slightly rephrased to make it more understandable :))
I have a need to compare two jasons, I want to display the diff, like we're used to see it in a typical file compare tool.
I have used the JsonDiffPatch from github (benjamine/jsondiffpatch), but could essentially use any other package. I get a diff
var diffPatch = new JsonDiffPatch();
diff = diffPatch.Diff(actualJson, expectedJson);
this diff makes total sense, it shows exactly which items are in conflict.
This I can then flatten, and run through, but I fail to identify each individual item in this dictionary in my original expectedJson:
var values = diff
.SelectTokens("$..*")
.Where(t => !t.HasValues)
.ToDictionary(t => t.Path, t => t.ToString());
foreach (var v in values)
{
Debug.WriteLine(v.ToString());
I was hoping to be able to look up the same path in my original 'actualJson' json snippet, so I could color code it in my output to indicate a conflict. But when I try to select by path from my actual, SelectToken don't seem to be finding anything (here diffActual becomes null):
var diffActual = actualJson.SelectToken(v.Key);
What am I missing here? :) Shouldn't the path of the diffPatch elements be the same as for original, or is it lost in the flattening? I clearly need some clues here.
Could there be other more obvious ways to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
