json.exists
This function checks whether the key or JSONPath is present in the JSON object. For the expression format, see https://github.com/oliveagle/jsonpath.
Syntax
json.exists(jsonObject, key)
Arguments
Argument |
Type |
Description |
---|---|---|
jsonObject |
any |
The JSON object. |
key |
string |
The key or JSONPath to check |
Returns
Type |
Description |
---|---|
boolean |
True, if the value is associated with the key or JSONPath. False otherwise. |
Examples
Let us say the jsonObject includes the following.
jsonObject =
{
"colors":
[
{ "id": 1, "value": "red" },
{ "id": 2, "value": "green" },
{ "id": 3, "value": "blue" }
]
}
In this case:
- The function
json.exists(jsonObject, "$loop.colors[?(@.value == 'red')].value[0]")
returnstrue
. - The function
json.exists(jsonObject, "$loop.colors[?(@.value == 'yellow')].value[0]")
returnsfalse
.