execute json xpath()

This function performs a JSONPath query b against an existing JSON object (under key a) in the internal cache.

For the return value of the function, see parameter c.

Parameters


Parameter

Description

a

The key name of the JSON object in the cache. See function "parse json and add to cache()".

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).

e

(optional) If the JSONPath query returns an array containing special characters, such as the / character, these are escaped with the \ character by default. You can prevent this behaviour with settings this parameter to true. Default: 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.