JSONPath Query
This activity allows you to extract information from a JSON-formatted payload when given the JSON to extract from and the JSON paths you want to be extracted. Instead of having to use complicated regular expressions to parse a JSON, you can use a JSONPath to traverse the JSON’s structure and extract the specific data you want.
Best Practices
Check the Continue Workflow Execution on Failure check box and use a Condition Block to check whether the path query was successful. Fail the workflow if the extraction was unsuccessful. This helps make sure your workflow fails with a useful error message.
Note: There are multiple implementations of JSONPath. Automation uses the Jayway implementation.
Helpful Links
- JSONPath Overview
- JSONPath Tester (More user-friendly but uses a slightly different implementation of JSONPath)
- JSONPath Tester (Jayway) (Not as user-friendly but uses the same implementation of JSONPath as Cisco XDR)
Usage
Enter the following properties to use this activity:
- General
- Display Name - Name displayed in the Workflow Editor for this activity.
- Description - Add a clear and useful description to provide meaningful information.
- Activity timeout (seconds) - Enter the amount of time in seconds that Automation will attempt to complete this activity before it times out.
- Continue workflow execution on failure - Check this check box to continue the workflow if this activity fails (optional).
- Skip activity execution - Check this check box to bypass running this activity during the workflow execution (optional).
- JSON Query
- Source JSON to Query - Paste the raw JSON content into the text box, or click the
(Variable Reference) icon and choose a variable containing the content.
- Source JSON to Query - Paste the raw JSON content into the text box, or click the
- JSONPath queries - Click Add and provide the following information to define how to extract data from your JSON using JSONPath syntax. Each query runs against the full input and returns the matching values:
- JSONPath Query - Enter the query, or click the
(Variable Reference) icon to use a variable.
- Property Name - Enter a name for the JSON property.
- Property Type - Click the drop-down menu and choose the data type of the value.
- Override with specified value if query doesn't return a result - Toggle this option on to set a default value (matching the data type) which is used as fallback data if the query returns no result (useful if anything downstream expects consistent structure).
- JSONPath Query - Enter the query, or click the
Once the activity has extracted the data, you can use it in a downstream activity by choosing the property in the Variable Browser.
For example, if you want to return the value from the workflow, use the Set Variables activity downstream to set the workflow's output variable to the value extracted from the JSON:
-
Under Variables, click Add.
-
In Variable to update, click the
(Variable Reference) icon and drill down to choose the desired workflow output variable.
-
In New value, click the
(Variable Reference) icon and drill down to choose the property from JSONPath Query under Activities.