Step-By-Step Guide to Use JSON to Retrieve a Key-value Pair

Let's consider an example of passing the JSON input manually and retrieving key-value pair from a specific path.

We are passing a JSON input that contains a store having details of books and bicycles.  We would retrieve details of the book available at the third book array of the JSON and its author name.

 

To retrieve the data from the JSON input:

1.    Create a new process.

2.    From the Canvas Tools panel, add the JSON Activity to the Flowchart designer on the Canvas.

3.    In the Parameter bar, create In arguments, outputstring and authorname of type String. These arguments are used to store the book details and name of the author respectively.

 

 

4.    In the JSON Action list, select Getter to perform the action of retrieving data.

5.    Select the check box beside JSON Input field to provide the input manually.

6.    Click the (Settings) icon, and then click Input JSON Editor to enter the JSON data manually. The JSONInputEditor dialog box appears.

 

 

7.    Enter the details of the books and the bicycles in JSON format and then click Confirm. You are directed back to the JSON activity in the Canvas.

8.    Click the (Settings) icon, and then click Output Mapping to align the JSON path and the data fetched with an argument. The Output Mapping dialog box opens.

9.    Click Add to provide details related to the mapping of the output parameters.

10.  In the JSONPath field, enter the JSON path expression, $..book[2] to retrieve the details of the third book available in the JSON array.

11.  In the Mapping Variable list, select outputstring defined in the Parameter bar. The mapped argument stores the data retrieved from the stated JSON path.

12.  Click Add.

13.  In the JSONPath field, enter the JSON path expression, $..book[2].author to retrieve the author name of the retrieved book.

14.  In the Mapping Variable list, select authorname defined in the Parameter bar. The mapped argument stores the data retrieved from the stated JSON path.

 

 

15.  Click CONFIRM to save the output mapping configuration.

To view the output in Automation Studio, let's add WriteLine activity for both the retrieved set of data. You can assign this process to a robot, if you want to execute this process outside Automation Studio.

16.  Add a WriteLine activity below the JSON Activity and in the Text field, enter outputstring to print the book details retrieved.

17.  Add another WriteLine activity below the first WriteLine activity and in the Text field, enter authorname to print the name of the author of the retrieved book.

18.  Save the process.

19.  Setup the environment and then perform test run.

 

 

The console displays the book details and the name of the author.

  Related Topics

JSON Activity