Build automation using JSON actions

In this example, we create a Task Bot using JSON actions to perform operations on the JSON data.

Procedure

  1. Create a bot
    1. On the left panel, click Automation.
      A list of available bots and forms is displayed.
    2. Click Create New > Bot.
    3. Provide a name for the bot: Json_Test_Bot.
    4. Click Create and Edit.
  2. 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:
        1. Value at 0: Reading
        2. Value at 1: Football
        3. 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.
  3. Double-click or drag the Dictionary > Put action to assign a value to a key in the dictionary.
    1. Select vSourceDictionary dictionary variable from the drop-down list.
    2. Enter tags in the Key field.
    3. Choose Variable tab and select vHobby value from the drop-down list.
  4. 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.
    1. Select vSourceDictionary dictionary variable from the drop-down list.
    2. In the Save the outcome to a variable field, Select vJson.
  5. 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$.
    Message box displaying JSON output
  6. Double click or drag the JSON > Start session action to start a JSON session.
    1. In the Data Source field, choose the Text option and press F2, and then select $vJson$.
    2. To create a JSON session, from JSON object session, select Local session and enter Default as the session name.
  7. Double-click or drag the JSON > Add node value action to add a new value to existing json.
    1. Enter $ in the JSON node path field.
    2. Enter address in the key name field.
    3. Select Dictionary variable from the Value type field.
    4. 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
    5. Choose Session name option and enter Default in the Session name field.
  8. Double click or drag JSON > Get node value action to retrieve the node values.
    1. Enter $ in the JSON node path field.
    2. Choose Session name option and enter Default in the Session name field.
    3. In the Save the outcome to a variable field, select SampleString.
  9. 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.
    Message box displaying the JSON output
  10. Double click or drag JSON > Update node value action to update a new value to existing Json.
    1. Enter tags in the JSON node path field.
    2. Select String variable from the Value type field.
    3. Enter Running in the Value (optional) field.
    4. Choose Session name option and enter Default in the Session name field.
  11. Double click or drag JSON > Update node value action to update a new value to existing Json.
    1. Enter LastName in the JSON node path field.
    2. Select String variable from the Value type field.
    3. Enter Wade in the Value (optional) field.
    4. Choose Session name option and enter Default in the Session name field.
  12. Double click or drag JSON > Get node value action to retrieve the node values.
    1. Enter $ in the JSON node path field.
    2. Choose Session name option and enter Default in the Session name field.
    3. In the Save the outcome to a variable field, select SampleString.
  13. 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.
    Message box displaying JSON output
  14. Double-click or drag JSON > Convert JSON to Dictionary action to convert JSON string into dictionary.
    1. Choose Session name option and enter Default in the Session name field.
    2. In the Save the outcome to a variable field, choose Dictionary option and select vDestinationDictionary from the drop-down list.
  15. Double-click or drag the Dictionary > Get action to verify if a key exists in a dictionary variable and return the corresponding value.
    1. Select vDestinationDictionary dictionary variable from the drop-down list.
    2. Enter address in the Key field.
    3. In the Assign the output to variable field, press F2 and select vAddressDictionary variable.
  16. 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}$
    
  17. 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.
    Message box displaying the JSON output
  18. Click Save and then click Run.