javascript - JSON patch rfc6902: Sequential operation and index -
in json patch, how should 1 use index subsequent operation on same array. 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 consider index of source, above indexes correct. when apply sequentially though, index incorrect. if remove, 0 th , 1st index, there no element @ index 2.
i think of couple of ways handle this. either group delete operation on array, keep temporary structure hold/manipulate change in index during deletion. or, keep index relative mutating value
[{"op":"remove","path":"/colors/0"}, {"op":"remove","path":"/colors/0"}, {"op":"remove","path":"/colors/0"}]
it makes sense if operation considered mutation of resource in sequence.
is there standard on this. cannot see in spec. a.4. removing array element
is there standard on this
the section evaluation of operations seems quite clear:
evaluation of json patch document begins against target json document. operations applied sequentially in order appear in array. each operation in sequence applied target document; resulting document becomes target of next operation.
Comments
Post a Comment