In JSON patch, how should one use the index for subsequent operation on the same array. For example, consider
var source = { colors: ['Red', 'Green', 'Blue'] };
var target = { colors: [] };
patch doc (operations)
[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/1"},
{"op":"remove","path":"/colors/2"}]
If I consider the index of the source, the above indexes are correct. When I apply it sequentially though, the index are incorrect. That is if I remove, 0 th and 1st index, there is no element at index 2.
I could think of couple of ways to handle this. Either group all delete operation on an array, then keep a temporary structure to hold/manipulate change in index during deletion. Or, keep the index relative to a mutating value
[{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"},
{"op":"remove","path":"/colors/0"}]
it makes sense if the operation is considered mutation of a resource in sequence.
Is there any standard on this. I cannot see anything about it in the spec. A.4. Removing an Array Element