Extract response data with JSONPath

When a response body content is JSON, JSONPath can be used to extract specific elements of the JSON into output parameters. The output parameters have a specified Blue Prism data type, and the object found using the JSONPath is converted to that data type. This example demonstrates how to extract data from a JSON HTTP response, storing it in stages in a process.

Configure the API definition response

An API definition returns the following JSON response:

To extract this data, select the Response for the required action in the API definition. Add a parameter for each data item selecting the appropriate data type and method.

View the response in Process Studio

In Process Studio, select the Outputs for the process that uses the Web API action for which the response was configured. Outputs have been added corresponding to the parameter name added to the response and the related data items have been created in the process to store each parameter.

When the process is run, data from the response is stored in the appropriate stage allowing it to be easily used elsewhere in the process.

If the JSONPath defined for the output parameter does not find a match in an HTTP response, the output parameter will return an empty data item/collection. If the JSONPath defined for the output parameter finds multiple possible matches in an HTTP response, an exception will be thrown in the process.

JSONPath syntax

Blue Prism supports the following syntax for JSONPath expressions:

JSONPath

Description

$

The root object or element.

@

The current object or element.

. or []

Child operator.

..

Recursive descent.

*

Wildcard.

[]

The native array operator.

[start:end:step]

Array slice operator.

?()

Applies a filter (script) expression.

()

Script expression, using the underlying script engine.

Example

A staff database contains a number of records that includes data about the employees of an organization.

{

"staff-database": {

"employee": [

{

"id": 1245,

"name": "Geoff Bryant",

"salary": 45000,

"age": 46

},

{

"id": 1365,

"name": "Tom Roberts",

"salary": 38000,

"job-title": "developer"

"age": 34

},

{

"id": 1287,

"name": "Herman Blunt",

"salary": 27000,

"job-title": "tester"

"age": 26

},

]

}

}

The following are examples of how JSONPath can be used to extract data.

JSONPath

Result

$.staff-database..salary Returns the salary for all employee records.
$.staff-database['employee'] Returns all employee records.
$..employee[?(@.job-title)] Filters all records with a job title.
$..employee[?(@.salary<40000)] Filters all records that have a salary of less than 40000.