Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
json-pointer
Advanced tools
The json-pointer npm package provides utilities for manipulating JSON data using JSON Pointers, which are strings that reference specific locations within a JSON document. This package allows you to get, set, and remove values in JSON objects using these pointers.
Get Value
This feature allows you to retrieve a value from a JSON object using a JSON Pointer string.
const jsonPointer = require('json-pointer');
const obj = { foo: { bar: 'baz' } };
const value = jsonPointer.get(obj, '/foo/bar');
console.log(value); // Output: 'baz'
Set Value
This feature allows you to set a value in a JSON object at the location specified by a JSON Pointer string.
const jsonPointer = require('json-pointer');
const obj = { foo: { bar: 'baz' } };
jsonPointer.set(obj, '/foo/bar', 'qux');
console.log(obj); // Output: { foo: { bar: 'qux' } }
Remove Value
This feature allows you to remove a value from a JSON object at the location specified by a JSON Pointer string.
const jsonPointer = require('json-pointer');
const obj = { foo: { bar: 'baz' } };
jsonPointer.remove(obj, '/foo/bar');
console.log(obj); // Output: { foo: {} }
The jsonpath package provides a way to query JSON documents using JSONPath expressions, which are similar to XPath expressions for XML. Unlike json-pointer, which uses a simpler pointer syntax, jsonpath offers more complex querying capabilities, such as filtering and recursive searches.
The json-query package allows you to query JSON objects using a simple query language. It supports nested queries, filtering, and joins. Compared to json-pointer, json-query offers more advanced querying features but may be more complex to use for simple get/set operations.
Lodash is a utility library that provides a wide range of functions for manipulating JavaScript objects, including deep property access and modification. While it is not specifically focused on JSON Pointers, it offers similar functionality through methods like _.get, _.set, and _.unset.
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-pointer
$ component install manuelstofer/json-pointer
var pointer = require('json-pointer');
Convenience wrapper around the api.
Calls .get
when called with an object
and a pointer
.
Calls .set
when also called with value
.
If only supplied object
, returns a partially applied function, mapped to the object.
var obj = {
existing: 'bla'
};
pointer(obj, '/new-value/bla', 'expected'); // .set a property
var objPointer = pointer(obj); // all api calls are now scoped to `obj`
objPointer('/existing') // gets '/existing' from `obj`
objPointer('/new-value/bla') // gets '/new-value/bla' from `obj`
Looks up a json pointer in an object
var obj = {
example: {
bla: 'hello'
}
};
pointer.get(obj, '/example/bla');
Sets a new value on object at the location described by pointer
var obj = {};
pointer.set(obj, '/example/bla', 'hello');
Creates a dictionary object (pointer -> value)
var obj = {
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
var obj = {
bla: 'hello'
};
pointer.has(obj, '/bla'); // -> true
pointer.has(obj, '/non/existing'); // -> false
Escapes 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 a array of reference tokens
pointer.parse('/hello/bla'); // -> ['hello', 'bla']
Builds a json pointer from a array of reference tokens
pointer.compile(['hello', 'bla']); // -> '/hello/bla'
FAQs
Some utilities for JSON pointers described by RFC 6901
The npm package json-pointer receives a total of 1,048,139 weekly downloads. As such, json-pointer popularity was classified as popular.
We found that json-pointer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.