Json Pointer
Here is a solid json-pointer implementation. The main differences to this implementation are
- conforms to RFC 6901
- throws an error when a value is not found / the pointer is invalid
- additional utilities
This json-pointer implementation will return undefined
if the pointer could not be resolved, which allows checks like
if (pointer.get(data, "#/path/to/nested/item") {...}
instead of
if (path && path.to && path.to.nested ...
.
This library exposes
- jsonpointer.get
- jsonpointer.set and
- jsonpointer.delete
install
npm i gold-json-pointer
pointer.get
var data = parent: child: title: "title of child" var titleOfChild = pointer; // "title of child"
pointer.set
set values on an object
var data = parent: children: title: "title of child" ; pointer; console; // 2
pointer.delete
delete properties or array items
pointer;
Helpers
pointer.join
pointer.join
joins all arguments to a valid json pointer:
var key = "child"; var target = pointer; // "#/parent/child/title"