Closed tomasbruckner closed 1 year ago
Ignoring properties is currently not supported, but I do have plan to add this feature (hopefully next version), and it shouldn't be hard to do.
In a nutshell, I was planning to add a property filter like jsondiffpatch has here in JsonDiffOptions
:
public Func<string, Context, bool>? PropertyFilter { get; set; }
A custom filter can get the property name and the diff context and return a boolean value to indicate whether to ignore the property.
I'm re-considering / restructuring the diff engine at the moment given my next priority is adding some support to JsonDocument
diff. It will make clear sense to me how the Context
can be defined to support both JsonNode
and JsonDocument
after this work.
@weichch This would be great to have PropertyFilter
.
Any progress on PropertyFilter
. It block me before using SystemTextJson.JsonDiffPatch
and event entire System.Text.Json
. Maybe I can help you with this feature?
Hi @WojciechNagorski
I actually prioritized this a little bit because it will be taking a bit longer to add JsonDocument
diff support than I thought.
I've done the changes locally, which I pushed it up just now #30, and released a preview version. I still need to add some tests in order to release a stable version.
Do both of you and @tomasbruckner mind providing some test cases you'd like the property filter to cover?
@weichch that's great to hear! Thanks for asking, it is very considerate! For me, the example from the first post is sufficient.
Seems like there is a quirk in array diff where the property filter is not applied to array items, because the the comparison is done using DeepEquals
not Diff
, though I should probably force it to use Diff
when PropertyFilter
is set.
I tested jsondiffpatch
also has the same issue. JsonDiffPatch.Net
works fine because it always does match-by-position on array items that are objects. The workaround (if I can't find an effective way to fix this issue) is setting ArrayObjectItemMatchByPosition
to true
.
For me it can works in the same way like in JsonDiffPatch.Net
Hi, is there a way to ignore properties from diff? The JsonDiffPatch does it here https://github.com/wbish/jsondiffpatch.net/blob/master/Src/JsonDiffPatchDotNet/JsonDiffPatch.cs#L332
What I am missing in the JsonDiffPatch is that it only allows you to exclude paths instead of properties which is a problem with recursive objects or arrays. To ignore property
foo
in an array of objectsyou would have to do
This is useful in some scenarios, but it would be amazing if there would also be an option to exclude properties by their name
The JsonDiffPatch looks abandoned so I am looking for an alternative that would support this scenario.
Is it something doable?