Some utilities for JSON pointers described by RFC 6901
Provides some additional stuff i needed but is not included in node-jsonpointer
$ npm install json-pointervarpointer=require('json-pointer');Looks up a JSON pointer in an object.
Array of reference tokens, e.g. returned by api.parse, can be passed as a pointer to .get, .set and .remove methods.
varobj={example: {bla: 'hello'}};pointer.get(obj,'/example/bla');Sets a new value on object at the location described by pointer.
varobj={};pointer.set(obj,'/example/bla','hello');Removes an attribute of object referenced by pointer.
varobj={example: 'hello'};pointer.remove(obj,'/example');// obj ->{}Creates a dictionary object (pointer -> value).
varobj={hello: {bla: 'example'}};pointer.dict(obj);// Returns://{// '/hello/bla': 'example'// }Just like:
each(pointer.dict(obj),iterator);Tests if an object has a value for a JSON pointer.
varobj={bla: 'hello'};pointer.has(obj,'/bla');// -> truepointer.has(obj,'/non/existing');// -> falseEscapes a reference token.
pointer.escape('hello~bla');// -> 'hello~0bla'pointer.escape('hello/bla');// -> 'hello~1bla'Unescape a reference token.
pointer.unescape('hello~0bla');// -> 'hello~bla'pointer.unescape('hello~1bla');// -> 'hello/bla'Converts a JSON pointer into an array of reference tokens.
pointer.parse('/hello/bla');// -> ['hello', 'bla']Builds a json pointer from an array of reference tokens.
pointer.compile(['hello','bla']);// -> '/hello/bla'Convenience wrapper around the api.
pointer(object)// bind objectpointer(object,pointer)// getpointer(object,pointer,value)// setThe wrapper supports chainable object oriented style.
varobj={anything: 'bla'};varobjPointer=pointer(obj);objPointer.set('/example','bla').dict();