
A fork of JSONPath from http://goessner.net/articles/JsonPath/
(see also licenses for dev. deps.)
Analyse, transform, and selectively extract data from JSON documents (and JavaScript objects).
jsonpath-plus expands on the original specification to add some
additional operators and makes explicit some behaviors the original
did not spell out.
Try the browser demo or Runkit (Node).
Please note: This project is not currently being actively maintained. We may accept well-documented PRs or some simple updates, but are not looking to make fixes or add new features ourselves.
^ for grabbing the parent of a matching item~ for grabbing property names of matching items (as array)@null(), @boolean(), @number(), @string(), @array(), @object()@integer()@scalar() (which also accepts undefined and
non-finite numbers when querying JavaScript objects as well as all of the basic non-object/non-function types)@other() usable in conjunction with a user-defined otherTypeCallback@undefined(), @function(), @nonFinite())@path/@parent/@property/@parentProperty/@root shorthand selectors within filters` for escaping remaining sequence@['...']/?@['...'] syntax for escaping special characters within
property names in filters$.. (getting all parent components)jsonpath-plus is consistently performant with both large and small datasets compared to other json querying libraries per json-querying-performance-testing. You can verify these findings by running the project yourself and adding more perf cases.
npm install jsonpath-plus
const {JSONPath} = require('jsonpath-plus');
const result = JSONPath({path: '...', json});
For browser usage you can directly include dist/index-browser-umd.cjs; no
Browserify magic is necessary:
<script src="node_modules/jsonpath-plus/dist/index-browser-umd.cjs"></script>
<script>
const result = JSONPath.JSONPath({path: '...', json: {}});
</script>
You may also use ES6 Module imports (for modern browsers):
<script type="module">
import {
JSONPath
} from './node_modules/jsonpath-plus/dist/index-browser-esm.js';
const result = JSONPath({path: '...', json: {}});
</script>
Or if you are bundling your JavaScript (e.g., with Rollup), just use,
noting that mainFields
should include browser for browser builds (for Node, the default, which
checks module, should be fine):
import {JSONPath} from 'jsonpath-plus';
const result = JSONPath({path: '...', json});
The full signature available is:
const result = JSONPath([options,] path, json, callback, otherTypeCallback);
The arguments path, json, callback, and otherTypeCallback
can alternatively be expressed (along with any other of the
available properties) on options.
Note that result will contain all items found (optionally
wrapped into an array) whereas callback can be used if you
wish to perform some operation as each item is discovered, with
the callback function being executed 0 to N times depending
on the number of independent items to be found in the result.
See the docs below for more on JSONPath's available arguments.
See also the API docs.
The properties that can be supplied on the options object or evaluate method (as the first argument) include: