JSON Pointer
This is an implementation of RFC-6901 JSON Pointer. JSON Pointer is designed for
referring to data values within a JSON document. It's designed to be URL
friendly so it can be used as a URL fragment that points to a specific part of
the JSON document.
Installation
npm install @hyperjump/json-pointer
Usage
const JsonPointer = require("@hyperjump/json-pointer");
const value = {
"foo": {
"bar": 42
}
};
const fooPointer = JsonPointer.append(JsonPointer.nil, "foo");
const fooBarPointer = JsonPointer.append(fooPointer, "bar");
const getFooBar = JsonPointer.get(fooBarPointer);
getFooBar(value);
const setFooBar = JsonPointer.set(fooBarPointer);
setFooBar(value, 33);
const assignFooBar = JsonPointer.assign(fooBarPointer);
assignFooBar(value, 33);
const unsetFooBar = JsonPointer.unset(fooBarPointer);
setFooBar(value);
const deleteFooBar = JsonPointer.delete(fooBarPointer);
setFooBar(value);
Contributing
Tests
Run the tests
npm test
Run the tests with a continuous test runner
npm test -- --watch