JSONPath, JSON Patch and JSON Pointer for JavaScript.
We follow RFC 9535 and test against the JSONPath Compliance Test Suite.
- Docs: https://jg-rp.github.io/json-p3/
- Install: https://jg-rp.github.io/json-p3/#install
- JSONPath playground: https://jg-rp.github.io/json-p3/playground
- JSONPath syntax: https://jg-rp.github.io/json-p3/guides/jsonpath-syntax
- API reference: https://jg-rp.github.io/json-p3/api
- Change log: https://github.com/jg-rp/json-p3/blob/main/CHANGELOG.md
- NPM: https://www.npmjs.com/package/json-p3
- Issue tracker: https://github.com/jg-rp/json-p3/issues
import { jsonpath } from "json-p3";
const expr = "$.users[?@.status == 'pending'].name";
const data = {
users: [
{ id: "usr_101", name: "Alice", status: "pending" },
{ id: "usr_102", name: "Bob", status: "active" },
{ id: "usr_103", name: "Charlie", status: "pending" },
],
};
const nodes = jsonpath.find(expr, data);
console.log(nodes.map((n) => n.value)); // [ "Alice", "Charlie" ]
console.log(nodes.map((n) => n.location)); // [ [ "users", 0, "name" ], [ "users", 2, "name" ] ]
console.log(nodes.map((n) => n.normalizedPath())); // [ "$['users'][0]['name']", "$['users'][2]['name']" ]
console.log(nodes.map((n) => n.shorthandPath())); // [ "$.users[0].name", "$.users[2].name" ]
console.log(nodes.map((n) => n.pointer.toString())); // [ "/users/0/name", "/users/2/name" ]Please see Contributing to JSON P3
json-p3 is distributed under the terms of the MIT license.