https://github.com/ashphy/jsonpath-js
An implementation of JSONPath
https://github.com/ashphy/jsonpath-js
Last synced: 5 months ago
JSON representation
An implementation of JSONPath
- Host: GitHub
- URL: https://github.com/ashphy/jsonpath-js
- Owner: ashphy
- License: mit
- Created: 2022-11-13T14:46:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-10-27T16:36:36.000Z (8 months ago)
- Last Synced: 2025-11-03T20:11:54.964Z (7 months ago)
- Language: TypeScript
- Homepage: https://jsonpath.com/
- Size: 668 KB
- Stars: 34
- Watchers: 2
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# jsonpath-js

[](https://www.npmjs.com/package/jsonpath-js)
[](https://github.com/ashphy/jsonpath-js/actions/workflows/lint.yml)
> [!WARNING]
> This library is still in its initial development stage, so please be aware that the API is subject to change.
An implementation of RFC 9535 [JSONPath](http://goessner.net/articles/JsonPath/)
## Try Online
You can test JSONPath expressions online at [https://jsonpath.com/](https://jsonpath.com/).
## Features
- 100% Compatible with RFC 9535
## Supported Runtimes
- Node v20+
- Deno v2+
- Bun v1.2+
## Install
```
npm install jsonpath-js
```
## Usage
```ts
import { JSONPathJS } from "jsonpath-js";
const query = new JSONPathJS("$.users[*].name");
const result = query.find({
users: [{ name: "John Doe" }, { name: "Jane Doe" }],
});
// [ 'John Doe', 'Jane Doe' ]
console.log(result);
const pathResult = query.paths({
users: [{ name: "John Doe" }, { name: "Jane Doe" }],
});
// [
// { value: "John Doe", path: "$['users'][0]['name']" },
// { value: "Jane Doe", path: "$['users'][1]['name']" },
// ];
console.log(pathResult);
const pathSegmentsResult = query.pathSegments({
users: [{ name: "John Doe" }, { name: "Jane Doe" }],
});
// NOTE: The root node $ is not included in the segments
// [
// { value: "John Doe", segments: ["users", 0, "name"] },
// { value: "Jane Doe", segments: ["users", 1, "name"] },
// ];
console.log(pathSegmentsResult);
```
## Contributing
Please read the [contributing guide](/docs/CONTRIBUTING.md).