Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
jsonpointer
Advanced tools
The jsonpointer npm package allows for direct manipulation and access of specific parts of a JSON document using the JSON Pointer syntax. It provides a simple way to fetch or modify values within a JSON object by specifying their paths. This can be particularly useful for working with deeply nested JSON structures, enabling precise and efficient data retrieval or updates without the need to traverse the entire object manually.
Get a value from a JSON document
This feature allows you to retrieve a value from a JSON document by specifying its JSON Pointer path. For example, using the path '/foo/bar' would return the value 'baz' from the given JSON document.
{"/foo/bar": "baz"}
Set a value in a JSON document
This feature enables you to set a value in a JSON document at a specified JSON Pointer path. For instance, setting the path '/foo/bar' to 'new value' would update the JSON document accordingly.
{"/foo/bar": "new value"}
Remove a value from a JSON document
This functionality allows for the removal of a value from a JSON document by specifying its JSON Pointer path. Using the path '/foo/bar' would remove the 'bar' property from the 'foo' object in the JSON document.
{"/foo/bar": null}
Lodash's get function offers similar functionality for retrieving values from a JSON object using a dot/path syntax. Unlike jsonpointer, it does not adhere to the JSON Pointer RFC 6901 standard and uses a different syntax for paths.
object-path is another npm package that provides methods to access and manipulate properties of objects. It supports both dot and bracket notation for paths, offering a more flexible syntax compared to jsonpointer's strict RFC 6901 compliance.
This is an implementation of JSON Pointer.
Looking to filter JSON from the command line? Check out jsonpointer-cli.
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
$ npm test
All tests pass.
$
(c) 2011-2021 Jan Lehnardt jan@apache.org & Marc Bachmann https://github.com/marcbachmann
Thanks to all contributors.
MIT License.
FAQs
Simple JSON Addressing.
The npm package jsonpointer receives a total of 5,136,948 weekly downloads. As such, jsonpointer popularity was classified as popular.
We found that jsonpointer 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.