Build a Task Bot that uses JSON actions to convert a dictionary to JSON, insert and update nodes, and convert the JSON back to a dictionary.
Before you begin
Procedure
- Log in to Control Room.
-
Perform the following steps to create a Task Bot:
-
Perform the following steps to create the required variables:
-
Double-click or drag the
action to assign a value to a key in the dictionary.
- Select the vSourceDictionary variable from the drop-down list.
- Enter tags in the Key field.
- Select the Variable tab, and then select vHobby as the value from the drop-down list.
-
Double-click or drag the
action to convert the dictionary variable to JSON and store it in
a string variable.
- Select the vSourceDictionary variable from the drop-down list.
- Select vJson in the Save the outcome to a variable field.
-
Double-click or drag the Message box
action to display the values.
- Enter $vJson$ in the Enter the message to display field.
-
Double-click or drag the action to start a JSON session.
- Select the Payload option and enter $vJson$.
- Retain Default as the session name in the Local session option.
-
Double-click or drag the
action to add a new value to the existing JSON.
-
Double-click or drag
action to retrieve the node values.
-
Double-click or drag the Message box
action to display the values.
- Enter $SampleString$ in the Enter the message to display field.
-
Double-click or drag
action to update a value in the existing JSON.
- Retain Default as the session name in the Session name field.
- Enter tags in the Node path field.
- Select String in the Value type drop-down.
- Enter Running in the Value (optional) field.
-
Double-click or drag
action to update a value in the existing JSON.
- Retain Default as the session name in the Session name field.
- Enter LastName in the Node path field.
- Select String in the Value type drop-down.
- Enter Wade in the Value (optional) field.
-
Double-click or drag
action to retrieve the node values.
- Retain Default as the session name in the Session name field.
- Enter $$ in the Node key or path field.
- Select SampleString in the Assign output to a variable field.
-
Double-click or drag the Message box
action to display the values.
- Enter $SampleString$ in the Enter the message to display field.
-
Double-click or drag
action to convert the JSON string to a dictionary.
- Retain Default as the session name in the Session name field.
- Select the Dictionary option, and then select vDestinationDictionary from the drop-down list in the Assign output to a variable field.
-
Double-click or drag the
action to verify whether a key exists in a dictionary variable
and return the corresponding value.
- Select vDestinationDictionary from the Dictionary variable drop-down.
- Enter address in the Key field.
- Select the vAddressDictionary variable from the Assign the output to variable drop-down.
-
Double-click or drag the Message box
action to display the values.
-
Double-click or drag
action to close the JSON session.
- Retain Default as the session name in the Session name field.
- Click Save to save the bot.
Results
- The Convert Dictionary to JSON action converts the data
in the vSourceDictionary variable to a JSON string and
saves it in the vJson variable. The message box displays
the string:
- The Insert node action inserts the
address key in the JSON string. The Get
node value action saves the updated JSON string in
SampleString. The message box displays its
contents:
- The Update node value action adds
Running to the tags list and
updates the LastName value to
Wade. The Get node value action
saves the updated JSON string in SampleString, and the
message box displays its contents:
- The Convert JSON to Dictionary action converts the
updated JSON string to a dictionary variable and saves the data in
vDestinationDictionary. The message box displays its
contents: