Skip to content
jg-rpPublic

About

JSONPath, JSON Patch and JSON Pointer for JavaScript

Topics

Resources

Contributing

Stars

31 stars

Watchers

2 watching

Forks

Repository files navigation

JSON P3

JSONPath, JSON Patch and JSON Pointer for JavaScript.
We follow RFC 9535 and test against the JSONPath Compliance Test Suite.

LICENSE Tests NPM npm type definitions


Links

Example

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" ]

Contributing

Please see Contributing to JSON P3

License

json-p3 is distributed under the terms of the MIT license.

About

JSONPath, JSON Patch and JSON Pointer for JavaScript

Topics

Resources

Contributing

Stars

31 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages