JSON Variables
JSON variables are custom flow variables of type JSON. You can create JSON variables in Flow Designer. For more information, see Create Custom Flow Variables.
You can use the following activities to store the data in JSON variable: HTTP Request, Parse, and Set Variable.
In HTTP and Parse activities, you can extract data using JSON path filter expression and store it in JSON variable.
In Set Variable activity, you can use the JSON variable in the Set Value option in the following ways:
-
Type in the JSON value in the text box. For example:
{ "userId":"rirani", "jobTitleName":"Developer", "firstName":"Romin", "lastName":"Irani", "preferredFullName":"Romin Irani", "employeeCode":"E1", "region":"CA", "phoneNumber":"408-xxxxx67", "emailAddress":"rirani@xyz.com" }
-
Use a Pebble expression.
Usage of JSON Variables in Pebble Expression
-
Dot(.) separated access: You can use dot(.) separated access in Pebble expression for JSON variable in call handling and flow control activities.
Syntax:
{{ jsonVariableName.fieldName }}
where,jsonVariableName.fieldName
should evaluate to a field in JSON variable.In the previous sample code snippet, if you extract the employee to a variable called
empvar
using HTTP or Parse:use
{{empvar.employeeCode}}
to get the value asE1
. -
Index access of JSON array: You can access a specific index from the JSON array similar to Pebble Syntax. For more details on Index Access in Pebble, visit https://pebbletemplates.io/wiki/guide/basic-usage/, for example:
If you extract the Employees JSON array into a variable called{ "Employees" : [ { "userId":"rirani", "jobTitleName":"Developer", "firstName":"Romin", "lastName":"Irani", "preferredFullName":"Romin Irani", "employeeCode":"E1", }, { "userId":"thanks", "jobTitleName":"Program Manager", "firstName":"Tom", "lastName":"Hanks", "preferredFullName":"Tom Hanks", "employeeCode":"E3", "directReports":[ { "userId":"John", "jobTitleName":"Developer", "firstName":"John", "lastName":"Irani", "preferredFullName":"John Irani", "employeeCode":"E2" }, { "userId":"Sam", "jobTitleName":"Developer", "firstName":"Sam", "lastName":"Das", "preferredFullName":"Sam Das", "employeeCode":"E2" } ] } ] }
var
using HTTP or Parse:-
Use
{{ var[0]}}
to get the employee details ofrirani
who is a manager. -
Use
{{ var[1].directReports[0] }}
to get the employee details ofJohn
who is a direct reportee of the manager. -
Use
{{ var[1].directReports[0].preferredFullName }}
to get the value asJohn Irani
. -
Use
{{ var[0].preferredFullName }}
to get the value asRomin Irani
.
-
Usage of JSON variable in HTTP request
To use a JSON variable as request body of a HTTP request, use the Set Variable activity first to convert the JSON variable to a string. For example, in the Set Variable activity Variable Settings section, set a variable jsonString
with value as {{ jsonVariable }}
.
Use this variable as an input to the HTTP settings. For example, in the HTTP Request Settings section, set the Request Body as {{ jsonString }}
.