Create a JSON expression variable
Use a JSON expression variable to retrieve required data from the JSON string.
To retrieve data, give any JSON string and retrieve the JSON values as per Expression text (JSON path). For processing JSON, a JSON path is required, like XPath for XML.
You can select a data object variable as your source JSON. You can also retrieve the value of a specific field within a data object variable using expression text as your input and return data type as your output.
JSON path uses special notation to represent nodes and their connections to adjacent nodes in a JSON path. There are two styles of notation, namely dot ($.name) and bracket ($['name'] or [name]. The dollar sign ($) represents the root member object.
- Open the process map in which to create the variable.
-
On the process modeling bar, click
Variables and click
New.
The New variable dialog box is displayed.
-
Enter a unique
Name for the variable.
By default, the name of the variable becomes the ID of the variable; however, you can change the ID if needed.
- On the Type list, select JSON expression. (Default: String)
- Optional. To use the variable for process initialization, select Initialization.
-
In the
Expression text field, enter the JSON string, such as
$.person.name, or
$['person']['age'].
At runtime, the data is retrieved as John or 25 respectively.
-
To specify the source to use in the JSON variable, select a process or string variable in the
Source JSON field.
For example, use the following string variable: { "person" : { "name" : "John" , "age" : 25 , "city" : "New York" }, "company" : "kofax" }You can set the source variable of JSON expression as output to an activity. You cannot delete a source JSON variable if it is in use in JSON expression variable.
- On the Return data type list, select the return type of the JSON expression which can use any of the following formats: Bool (default), Byte, Currency, Date, Decimal, Double, Float, Long, Short, or String.
-
Click
Add and close.
The New variable dialog box is closed.
- Save the process.