json Functions

Use json functions in rules to manipulate JSON at runtime. For example, find all the JSON paths in a dashboard that have a link widget and update the links at runtime.

searchPaths 

Parameters: String jsonPath

Returns: Collection<String>

Recursive: Not supported

Description: Searches the current JSON document and returns matching fully qualified JSON paths. If no results are found, returns an empty array. If more than one item is found, returns an array of JSON paths.

Example 

1{
2    "searchPaths": "${json:searchPaths('$.state.widget..[?(@.type in [\"link\"])]')}"
3}

run on a dashboard returns all JSON paths in the dashboard with link widgets:

1{
2    "searchPaths": ["$['state']['widgets']['link3']", "$['state']['widgets']['link4']", "$['state']['widgets']['link1']", "$['state']['widgets']['link2']" ]
3}

These paths can be used to make runtime updates to the links in the dashboard.

searchValues 

Parameters: String jsonPath

Returns: Collection<Object>

Recursive: Not supported

Description: Searches the current JSON document and returns values of the matching nodes. If no results are found, returns an empty array. If more than one item is found, returns an array of objects. This function throws an error when called outside rules execution.

Example 

1{
2    "searchValues": "${json:searchValues('$.path.to.json.object')}"
3}

toJsonObject 

Parameters: Object object

Returns: Object

Recursive: Not supported

Description: Converts a string to a JSON object

Example 

1{
2    "jsonObject": "${json:toJsonObject('{\"type\" : \"fruit\",\"color\" : \"red\"}')}"
3}

Returns

1{
2    "jsonObject": {
3        "type" : "fruit",
4        "color" : "red"
5    }
6}