A JavaScript implementation to create json patches of the JSON Media Type for partial modifications: http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08. See also https://github.com/bruth/jsonpatch-js.
Given these two JSON objects:
{
"authorities": ["ROLE_ADMIN",
"ROLE_POWERUSER",
"ROLE_USER"],
"id": 2,
}
{
"authorities": ["ROLE_USER"],
"id": 2,
}
JSONdiff produces this patch:
[{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/2"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]
The problem is that, according to http://tools.ietf.org/html/rfc6902#page-6:
If removing an element from an array, any elements above the
specified index are shifted one position to the left.
So this should actually be:
[{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/1"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]
Removing number 1 twice.
It would, of course, also be valid to work in reverse and always remove from higher indices first.
Hi,
Given these two JSON objects: { "authorities": ["ROLE_ADMIN", "ROLE_POWERUSER", "ROLE_USER"], "id": 2, }
{ "authorities": ["ROLE_USER"], "id": 2, }
JSONdiff produces this patch: [{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/2"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]
The problem is that, according to http://tools.ietf.org/html/rfc6902#page-6: If removing an element from an array, any elements above the specified index are shifted one position to the left.
So this should actually be: [{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/1"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]
Removing number 1 twice.
It would, of course, also be valid to work in reverse and always remove from higher indices first.
Jim