https://github.com/icholy/jsonpatch.js
experimenting with slices in Json pointers and patches
https://github.com/icholy/jsonpatch.js
Last synced: 3 months ago
JSON representation
experimenting with slices in Json pointers and patches
- Host: GitHub
- URL: https://github.com/icholy/jsonpatch.js
- Owner: icholy
- Created: 2013-02-28T06:42:36.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-10-30T04:33:42.000Z (over 10 years ago)
- Last Synced: 2025-02-12T11:14:32.834Z (5 months ago)
- Language: JavaScript
- Homepage: http://choly.ca/JsonPatch.js/
- Size: 238 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JsonPatch with Slices (this is an experiment) [](https://travis-ci.org/icholy/JsonPatch.js)
This is loosely based on the [json-patch](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-05) draft.
The project was motivated by an [earlier rant](https://gist.github.com/icholy/5050533)
**Original Data**
``` javascript
var JsonPatch = require('jsonpatch'),
patcher = new JsonPatch();var someData = {
foo: [
{ x: 1 },
{ y: 2 }
]
};
```**Remove slice**
``` javascript
patcher.apply(someData, [{ op: 'remove', path: '/foo/0:2'}] );// resulting object
{
foo: [],
}
```**Move slice contents**
``` javascript
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](https://github.com/icholy/JsonPatch.js/blob/master/test/example.js)