execute json xpath(key a, expression b, array as text c, ignore exception d)
Group |
Performs a JSONPath query b against an existing JSON object (under key a) in the internal cache. See function parse json and add to cache(data a, key b).
For the return value of the function, see parameter c.
Parameter Description
Parameter |
Description |
a |
The key name of the JSON object in the cache. See function parse json and add to cache(data a, key b). |
b |
The JSONPath query. See https://github.com/json-path/JsonPath. |
c |
(optional) If true, the result of the query is returned as a JSON string. If false, the number of elements in the result JSON array or the number of key-value pairs in the result JSON object is returned. Default: false. Alternatively, you can specify the name of a map in this parameter if the result of the query is an object. The key-value pairs of the object are then written into this map. The return value of the function will then be the number of these key-value pairs. See examples below for illustration. |
d |
If true, exceptions are ignored and an empty string is returned. Default: <empty> (== false). |
Examples
File:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
Parameter b : $.store.book[*].author
Parameter c : true
Result: ["Nigel Rees","Evelyn Waugh","Herman Melville","J. R. R. Tolkien"]
Note: The result of the query is an array with 4 elements.
Parameter b : $.store.book[*].author
Parameter c : false
Result: 4
Parameter b: $.store.book[0].['author','title']
Parameter c: true
Result: {author=Nigel Rees, title=Sayings of the Century}
Note: The result of the query is an object with 2 key-value pairs.
Parameter b: $.store.book[0].['author','title']
Parameter c: false
Result: 2
Parameter b: $.store.book[0].['author','title']
Parameter c: mymap
Result: 2
Note: The map mymap now contains the two key-value pairs author=Nigel Rees and title=Sayings of the Century.