Eric Foster 35b96bc934 initial commit | vor 6 Jahren | |
---|---|---|
.. | ||
LICENSE.md | vor 6 Jahren | |
README.md | vor 6 Jahren | |
jsonpointer.js | vor 6 Jahren | |
package.json | vor 6 Jahren |
This is an implementation of JSON Pointer.
var jsonpointer = require('jsonpointer');
var obj = { foo: 1, bar: { baz: 2}, qux: [3, 4, 5]};
jsonpointer.get(obj, '/foo'); // returns 1
jsonpointer.get(obj, '/bar/baz'); // returns 2
jsonpointer.get(obj, '/qux/0'); // returns 3
jsonpointer.get(obj, '/qux/1'); // returns 4
jsonpointer.get(obj, '/qux/2'); // returns 5
jsonpointer.get(obj, '/quo'); // returns undefined
jsonpointer.set(obj, '/foo', 6); // sets obj.foo = 6;
jsonpointer.set(obj, '/qux/-', 6) // sets obj.qux = [3, 4, 5, 6]
var pointer = jsonpointer.compile('/foo')
pointer.get(obj) // returns 1
pointer.set(obj, 1) // sets obj.foo = 1
$ node test.js
All tests pass.
$
(c) 2011-2015 Jan Lehnardt jan@apache.org & Marc Bachmann https://github.com/marcbachmann
MIT License.