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