This is loosely based on the json-patch draft.
The project was motivated by an earlier rant
Original Data
var JsonPatch = require('jsonpatch'),
patcher = new JsonPatch();
var someData = {
foo: [
{ x: 1 },
{ y: 2 }
]
};
Remove slice
patcher.apply(someData, [{ op: 'remove', path: '/foo/0:2'}] );
// resulting object
{
foo: [],
}
Move slice contents
patcher.apply(someData, [{ op: 'move', path: '/foo/0:2/x', to: '/bar' }] );
// resulting object
{
foo: [
{},
{}
],
bar: [1, 2]
}
Slices can be used with the other operations too:
add
remove
replace
move
copy
See more examples in the tests