Build automation using JSON actions
- Updated: 2024/07/15
Build automation using JSON actions
In this example, we create a Task Bot using JSON actions to perform operations on the JSON data.
Procedure
-
Create a bot
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create New > Bot.
- Provide a name for the bot: Json_Test_Bot.
- Click Create and Edit.
-
On the left panel, click Automation.
-
Create the following variables:
- vSourceDictionary
- Type: Dictionary
- Subtype: Any
- Variable name: vSourceDictionary
- Default values:
Type Key Value String firstName Mathew String LastName Brain Number id 5669 Boolean isAdmin True
- vHobby
- Type: List
- Subtype: String
- Default values:
- Value at 0: Reading
- Value at 1: Football
- Value at 2: Cooking
- vJson
- Type: String
- Name: vJson
- vAddressDictionary
- Type: Dictionary
- Subtype: Any
- Name: vAddressDictionary
- vDestinationDictionary
- Type: Dictionary
- Subtype: Any
- Name: vDestinationDictionary
- Create a SampleString and a SampleNumber variable.
- vSourceDictionary
-
Double-click or drag the Dictionary > Put
action to assign a value to a key in the dictionary.
- Select vSourceDictionary dictionary variable from the drop-down list.
- Enter tags in the Key field.
- Choose Variable tab and select vHobby value from the drop-down list.
-
Double-click or drag the JSON > Convert Dictionary to JSON
action to convert the dictionary variable to JSON and store it in
a string variable.
- Select vSourceDictionary dictionary variable from the drop-down list.
- In the Save the outcome to a variable field, Select vJson.
- Double-click or drag the Message box action to print the values. In the Enter the message to display field, press F2, and then select $vJson$.
-
Double click or drag the JSON > Start session action to start a JSON session.
- In the Data Source field, choose the Text option and press F2, and then select $vJson$.
- To create a JSON session, from JSON object session, select Local session and enter Default as the session name.
-
Double-click or drag the JSON > Add node value
action to add a new value to existing json.
- Enter $ in the JSON node path field.
- Enter address in the key name field.
- Select Dictionary variable from the Value type field.
-
In the Value field, select
Dictionary tab and enter the following
values:
Type Key Value String City Huston String State Texas String Country US Number Pincode 100233 Boolean isPermenentAddress True - Choose Session name option and enter Default in the Session name field.
-
Double click or drag JSON > Get node value
action to retrieve the node values.
- Enter $ in the JSON node path field.
- Choose Session name option and enter Default in the Session name field.
- In the Save the outcome to a variable field, select SampleString.
- Double-click or drag the Message box action to print the values. In the Enter the message to display field, press F2, and then select SampleString.
-
Double click or drag JSON > Update node value
action to update a new value to existing Json.
- Enter tags in the JSON node path field.
- Select String variable from the Value type field.
- Enter Running in the Value (optional) field.
- Choose Session name option and enter Default in the Session name field.
-
Double click or drag JSON > Update node value
action to update a new value to existing Json.
- Enter LastName in the JSON node path field.
- Select String variable from the Value type field.
- Enter Wade in the Value (optional) field.
- Choose Session name option and enter Default in the Session name field.
-
Double click or drag JSON > Get node value
action to retrieve the node values.
- Enter $ in the JSON node path field.
- Choose Session name option and enter Default in the Session name field.
- In the Save the outcome to a variable field, select SampleString.
- Double-click or drag the Message box action to print the values. In the Enter the message to display field, press F2, and then select SampleString.
-
Double-click or drag JSON > Convert JSON to Dictionary
action to convert JSON string into dictionary.
- Choose Session name option and enter Default in the Session name field.
- In the Save the outcome to a variable field, choose Dictionary option and select vDestinationDictionary from the drop-down list.
-
Double-click or drag the Dictionary > Get
action to verify if a key exists in a dictionary variable and
return the corresponding value.
- Select vDestinationDictionary dictionary variable from the drop-down list.
- Enter address in the Key field.
- In the Assign the output to variable field, press F2 and select vAddressDictionary variable.
-
Double-click or drag the Message box
action to print the values. In the Enter the message
to display field, enter:
Output Dictionary: Size :$vDestinationDictionary.Dictionary:size.Number:toString$ Key[id]: $vDestinationDictionary{id}$ Key[address.city]: $vAddressDictionary{city}$
- Double click or drag JSON > End session action to close the JSON session. Choose Session name option and enter Default in the session name field.
- Click Save and then click Run.