Say I have an entity that looks like this:
{
"list": ["foo", "qux", "bar"]
}
If I want to remove "foo"
and "bar"
using one JSON patch with two operations. What is the correct syntax?
Option 1
This option expects the indexes to be immutable while the operations are being invoked.
[
{ "op": "remove", "path": "/list/0" }, // removes "foo"
{ "op": "remove", "path": "/list/2" } // removes "bar" using original index
]
Option 2
This option expects the indexes to shift after the first operation has been invoked.
[
{ "op": "remove", "path": "/list/0" }, // removes "foo"
{ "op": "remove", "path": "/list/1" } // removes "bar" using new index
]
Option 3
This option expects unexpected behavior could occur and guards itself.
[
{ "op": "remove", "path": "/list/2" }, // removes "bar" first to ignore shifting indexes
{ "op": "remove", "path": "/list/0" } // removes "foo"
]
Option 3 is the safest option, I'm just mostly curious about what is correct. The RFC for JSON patch isn't clear on this.