jsonpath-plus
The JSONPath Plus built-in module is available only inside a PubNub Function. Import it with require('jsonpath'), not require('jsonpath-plus').
1const { JSONPath } = require('jsonpath');
JSONPath
JSONPath({path, json})
* required
| Parameter | Description |
|---|---|
path *Type: String | JSONPath expression. |
json *Type: Object | JSON document or JavaScript object to query. |
Returns: an array of matched values.
1const { JSONPath } = require('jsonpath');
2
3const json_sample = {
4 store: {
5 book: [
6 { category: 'reference', author: 'Nigel Rees', price: 8.95 },
7 { category: 'fiction', author: 'Evelyn Waugh', price: 12.99 },
8 ],
9 },
10};
11
12export default req => {
13 const result = JSONPath({ path: '$.store.book[*].author', json: json_sample });
14 // result: ['Nigel Rees', 'Evelyn Waugh']
15 return req.ok({ result });
show all 16 linesRelated reference
- Modules and libraries. Every built-in module available inside a Function.