You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System.Text.Json.JsonDiffPatch.Diffs.Formatters;
using System.Text.Json.JsonDiffPatch;
using System.Text.Json.Nodes;
string json1 = "{ \"id\": 1, \"name\": \"Some name\", \"projects\": [{\"id\": 88, \"name\": \"bar\"}] }";
string json2 = "{ \"id\": 1, \"name\": \"Some name\", \"projects\": [{\"id\": 77, \"name\": \"foo\"}, {\"id\": 88, \"name\": \"bar z\"}] }";
// project with id 77 inserted first in the array, name for project with id 88 changed from "bar" to "bar z"
object? IdKeyFinder(JsonNode? n, int i)
{
if (n is JsonObject obj
&& obj.TryGetPropertyValue("id", out var value))
{
return value?.ToString();
}
return null;
}
var diff = JsonDiffPatcher.Diff(
json1,
json2,
new JsonPatchDeltaFormatter(),
new JsonDiffOptions
{
JsonElementComparison = JsonElementComparison.RawText,
ArrayObjectItemMatchByPosition = false,
ArrayObjectItemKeyFinder = IdKeyFinder
});
The text was updated successfully, but these errors were encountered:
When using ArrayObjectItemKeyFinder with test data like below, System.FormatException: 'Invalid patch document.' is thrown
json1
{ "id": 1, "name": "Some name", "projects": [{"id": 88, "name": "bar"}] }
json2
{ "id": 1, "name": "Some name", "projects": [{"id": 77, "name": "foo"}, {"id": 88, "name": "bar z"}] }
Code to reproduce:
The text was updated successfully, but these errors were encountered: