Gathering detailed insights and metrics for jsonpath
Gathering detailed insights and metrics for jsonpath
Gathering detailed insights and metrics for jsonpath
Gathering detailed insights and metrics for jsonpath
Query and manipulate JavaScript objects with JSONPath expressions. Robust JSONPath engine for Node.js.
npm install jsonpath
Typescript
Module System
Node Version
NPM Version
JavaScript (99.99%)
Dockerfile (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,387 Stars
104 Commits
218 Forks
24 Watchers
2 Branches
10 Contributors
Updated on Jun 25, 2025
Latest Version
1.1.1
Package Id
jsonpath@1.1.1
Unpacked Size
393.83 kB
Size
93.39 kB
File Count
30
NPM Version
6.14.11
Node Version
10.24.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.
1var cities = [ 2 { name: "London", "population": 8615246 }, 3 { name: "Berlin", "population": 3517424 }, 4 { name: "Madrid", "population": 3165235 }, 5 { name: "Rome", "population": 2870528 } 6]; 7 8var jp = require('jsonpath'); 9var names = jp.query(cities, '$..name'); 10 11// [ "London", "Berlin", "Madrid", "Rome" ]
Install from npm:
1$ npm install jsonpath
Here are syntax and examples adapted from Stefan Goessner's original post introducing JSONPath in 2007.
JSONPath | Description |
---|---|
$ | The root object/element |
@ | The current object/element |
. | Child member operator |
.. | Recursive descendant operator; JSONPath borrows this syntax from E4X |
* | Wildcard matching all objects/elements regardless their names |
[] | Subscript operator |
[,] | Union operator for alternate names or array indices as a set |
[start:end:step] | Array slice operator borrowed from ES4 / Python |
?() | Applies a filter (script) expression via static evaluation |
() | Script expression via static evaluation |
Given this sample data set, see example expressions below:
1{ 2 "store": { 3 "book": [ 4 { 5 "category": "reference", 6 "author": "Nigel Rees", 7 "title": "Sayings of the Century", 8 "price": 8.95 9 }, { 10 "category": "fiction", 11 "author": "Evelyn Waugh", 12 "title": "Sword of Honour", 13 "price": 12.99 14 }, { 15 "category": "fiction", 16 "author": "Herman Melville", 17 "title": "Moby Dick", 18 "isbn": "0-553-21311-3", 19 "price": 8.99 20 }, { 21 "category": "fiction", 22 "author": "J. R. R. Tolkien", 23 "title": "The Lord of the Rings", 24 "isbn": "0-395-19395-8", 25 "price": 22.99 26 } 27 ], 28 "bicycle": { 29 "color": "red", 30 "price": 19.95 31 } 32 } 33}
Example JSONPath expressions:
JSONPath | Description |
---|---|
$.store.book[*].author | The authors of all books in the store |
$..author | All authors |
$.store.* | All things in store, which are some books and a red bicycle |
$.store..price | The price of everything in the store |
$..book[2] | The third book |
$..book[(@.length-1)] | The last book via script subscript |
$..book[-1:] | The last book via slice |
$..book[0,1] | The first two books via subscript union |
$..book[:2] | The first two books via subscript array slice |
$..book[?(@.isbn)] | Filter all books with isbn number |
$..book[?(@.price<10)] | Filter all books cheaper than 10 |
$..book[?(@.price==8.95)] | Filter all books that cost 8.95 |
$..book[?(@.price<30 && @.category=="fiction")] | Filter all fiction books cheaper than 30 |
$..* | All members of JSON structure |
Find elements in obj
matching pathExpression
. Returns an array of elements that satisfy the provided JSONPath expression, or an empty array if none were matched. Returns only first count
elements if specified.
1var authors = jp.query(data, '$..author'); 2// [ 'Nigel Rees', 'Evelyn Waugh', 'Herman Melville', 'J. R. R. Tolkien' ]
Find paths to elements in obj
matching pathExpression
. Returns an array of element paths that satisfy the provided JSONPath expression. Each path is itself an array of keys representing the location within obj
of the matching element. Returns only first count
paths if specified.
1var paths = jp.paths(data, '$..author'); 2// [ 3// ['$', 'store', 'book', 0, 'author'] }, 4// ['$', 'store', 'book', 1, 'author'] }, 5// ['$', 'store', 'book', 2, 'author'] }, 6// ['$', 'store', 'book', 3, 'author'] } 7// ]
Find elements and their corresponding paths in obj
matching pathExpression
. Returns an array of node objects where each node has a path
containing an array of keys representing the location within obj
, and a value
pointing to the matched element. Returns only first count
nodes if specified.
1var nodes = jp.nodes(data, '$..author'); 2// [ 3// { path: ['$', 'store', 'book', 0, 'author'], value: 'Nigel Rees' }, 4// { path: ['$', 'store', 'book', 1, 'author'], value: 'Evelyn Waugh' }, 5// { path: ['$', 'store', 'book', 2, 'author'], value: 'Herman Melville' }, 6// { path: ['$', 'store', 'book', 3, 'author'], value: 'J. R. R. Tolkien' } 7// ]
Returns the value of the first element matching pathExpression
. If newValue
is provided, sets the value of the first matching element and returns the new value.
Returns the parent of the first matching element.
Runs the supplied function fn
on each matching element, and replaces each matching element with the return value from the function. The function accepts the value of the matching element as its only parameter. Returns matching nodes with their updated values.
1var nodes = jp.apply(data, '$..author', function(value) { return value.toUpperCase() }); 2// [ 3// { path: ['$', 'store', 'book', 0, 'author'], value: 'NIGEL REES' }, 4// { path: ['$', 'store', 'book', 1, 'author'], value: 'EVELYN WAUGH' }, 5// { path: ['$', 'store', 'book', 2, 'author'], value: 'HERMAN MELVILLE' }, 6// { path: ['$', 'store', 'book', 3, 'author'], value: 'J. R. R. TOLKIEN' } 7// ]
Parse the provided JSONPath expression into path components and their associated operations.
1var path = jp.parse('$..author'); 2// [ 3// { expression: { type: 'root', value: '$' } }, 4// { expression: { type: 'identifier', value: 'author' }, operation: 'member', scope: 'descendant' } 5// ]
Returns a path expression in string form, given a path. The supplied path may either be a flat array of keys, as returned by jp.nodes
for example, or may alternatively be a fully parsed path expression in the form of an array of path components as returned by jp.parse
.
1var pathExpression = jp.stringify(['$', 'store', 'book', 0, 'author']); 2// "$.store.book[0].author"
This implementation aims to be compatible with Stefan Goessner's original implementation with a few notable exceptions described below.
Script expressions (i.e, (...)
and ?(...)
) are statically evaluated via static-eval rather than using the underlying script engine directly. That means both that the scope is limited to the instance variable (@
), and only simple expressions (with no side effects) will be valid. So for example, ?(@.length>10)
will be just fine to match arrays with more than ten elements, but ?(process.exit())
will not get evaluated since process
would yield a ReferenceError
. This method is even safer than vm.runInNewContext
, since the script engine itself is more limited and entirely distinct from the one running the application code. See more details in the implementation of the evaluator.
This project uses a formal BNF grammar to parse JSONPath expressions, an attempt at reverse-engineering the intent of the original implementation, which parses via a series of creative regular expressions. The original regex approach can sometimes be forgiving for better or for worse (e.g., $['store]
=> $['store']
), and in other cases, can be just plain wrong (e.g. [
=> $
).
As a result of using a real parser and static evaluation, there are some arguable bugs in the original library that have not been carried through here:
step
arguments in slice operators may now be negative.
and @
characters not referring to instance variables$['$']
instead of $.$
)No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More