Example of using JSON package actions in a bot

Build a bot that runs a JSON script with multiple records. In this example, we use a JSON file that contains a list of feeds from a blog, and the bot extracts the required information from the JSON file and prints it to a message box.

Prerequisites

To run JSON script from Automation 360, you must already have the JSON data stored either as a variable or a file (.json, .txt format) on your desktop. The following screenshot displays the structure of a JSON object as a sample.
{
    "feeds": [
	
        {
            "id": 1090,
            "title": "Amsterdam Beaches",
            "description": "It’s true that few people think of the Netherlands when planning a beach holiday. But whether you’re just visiting or lucky enough to call this iconic city home, there are plenty of great beaches to enjoy in Amsterdam",
            "location": "Kloveniersburgwal 1, 1012 CW Amsterdam, Netherlands",
            "lng": 0,
            "lat": 0,
            "userId": 3043,
            "name": "Ritu singh",
            "isdeleted": false,
            "profilePicture": "/Images/userimageicon.png",
            "videoUrl": null,
            "images": null,
            "mediatype": 0,
            "imagePaths": null,
            "feedsComment": null,
            "commentCount": 3,
            "multiMedia": [
                {
                    "id": 2157,
                    "name": "beach of amsterdam.PNG",
                    "description": null,
                    "url": "feedsmedia/3043/c5522956-4ab5-408e-b540-16a8c90af9b0.PNG",
                    "mediatype": 1,
                    "likeCount": 0,
                    "place": null,
                    "createAt": "0001-01-01T00:00:00"
                }
            ],
            "likeDislike": {
                "likes": 2,
                "dislikes": 1,
                "userAction": 2
            },
            "createdAt": "2019-12-26T07:08:38.4659686",
            "code": 0,
            "msg": null
        }
		],
    "totalFeed": 125
}

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: JsonBot.
    4. Click Create and Edit.
  2. Start a JSON session by using the JSON > Start session action.
    1. From the Actions pane, double-click or drag the JSON > Start session action.
    2. In the Data Source field, choose File and select the Desktop file file type. Click Browse to find your JSON file, for example, D:\userdefined\My Downloads\Sample Json with 200 Records.json.
    3. To create a JSON session, from Json object session, select Local session and enter Default as the session name.
  3. Create a variable: SampleString
    • Type: String
    • Name: SampleString
  4. Retrieve the value of the total number of feeds from the JSON script by using the JSON > Get node value action.
    1. From the Actions pane, double-click or drag the JSON > Get node value action.
    2. In the JSON node key or path field, enter totalFeed.
    3. In the Session name field, enter Default.
    4. In the Save the outcome to a variable field, select SampleString.
    5. To print the value of totalFeed, double-click or drag the Message box action.
    6. To open the list of your variables, in the Enter the message to display field, press F2, and then select SampleString.
    7. Click Yes, insert.
    Using Get node action
  5. To retrieve any specific value from 125 feeds, perform the following steps.
    1. From the Actions pane, double-click or drag the JSON > Get node value action.
    2. In the JSON node key or path field, enter feeds[52].title.
    3. In the Session name field, enter Default.
    4. In the Save the outcome to a variable field, select SampleString.
    5. To print the value of feeds[52].title, double-click or drag the Message box action.
    6. To open the list of your variables, in the Enter the message to display field, press F2, and then select SampleString.
    7. Click Yes, insert.
    Extracting the value of title
  6. Create a variable: StringList
    • Type: List
    • Subtype: String
    • Name: StringList
  7. To retrieve the list of child nodes from a node path, use the JSON > Get node list action.
    1. From the Actions pane, double-click or drag the JSON > Get node list action.
    2. In the JSON node key or path field, enter feeds.
    3. In the Session name field, enter Default.
    4. In the Save the outcome to a variable field, select StringList.
    5. To print all the child nodes under the feed 51 object, double-click or drag the Message box action.
    6. To open the list of your variables, in the Enter the message to display field, press F2, and then select StringList[51].
    7. Click Yes, insert.
    Using Get node list action
  8. To close a JSON session, use End session. In the Session name field, enter Default.
  9. Click Save and then click Run.
  10. Start a new JSON session.
    1. From the Actions pane, double-click or drag the JSON > Start session action. In the Data Source field, select Text and enter StringList[52].
    2. From Json object session, select Local session and enter Default 1 as the session name.
  11. To retrieve the value from a specific node, use JSON > Get node value.
    1. From the Actions pane, double-click or drag the JSON > Get node value action.
    2. In the JSON node key or path field, enter description.
    3. In the Session name field, enter Default 1.
    4. In the Save the outcome to a variable field, select SampleString.
    5. To print the value of the description node, double-click or drag the Message box action.
    6. To open the list of your variables, in the Enter the message to display field, press F2, and then select SampleString.
    7. Click Yes, insert.
    Extracting a specific node value from the list
  12. To close the JSON session, use End session. In the Session name field, enter Default 1.
  13. Click Save and the click Run.
    You can further perform operations to extract the required information from the JSON feed and use the extracted values in your bot. To extract the name value from feed 50 through 60, perform the following steps.
  14. Create a variable: ListItem
    • Type: String
    • Name: ListItem
  15. To process each item in the list, use the Loop action.
    1. Double-click or drag the Loop action.
    2. Select the For each item in the list iterator.
    3. In the List field, select StringList.
    4. Choose the Range option and for the following fields, enter the values provided:
      • From Index: 50
      • To index: 60
    5. In the Assign the current value to variable field, select ListItem.
  16. Start a new JSON session.
    1. From the Actions pane, double-click or drag the JSON > Start session action.
    2. In the Data Source field, select Text and enter ListItem.
    3. To create a JSON session, from Json object session, select Local session and enter Default 2 as the session name.
  17. To retrieve the value from a specific node, use the JSON > Get node value action .
    1. From the Actions pane, double-click or drag the JSON > Get node value action.
    2. In the JSON node key or path field, enter name.
    3. In the Session name field, enter Default 2.
    4. In the Save the outcome to a variable field, select SampleString.
    5. To print the value of the name node, double-click or drag the Message box action.
    6. To open the list of your variables, in the Enter the message to display field, press F2 , and then select SampleString.
    7. Click Yes, insert.
  18. Click Save and then click Run.
    The name values retrieved from the feeds 50 through 60 are as follows:
    Feeds (object) Name
    50 Ashish
    51 Sophia
    52 Ritu
    53 Shivam
    54 Navya
    55 Faiz
    56 Martin
    57 Shweta
    58 Jagjit
    59 Mark
    60 Sophia