In this session, we'll look at how to use the JSON Object Manager package available for download from Bot Store. This package can be used for retrieving data from the JSON response of a REST web service call, reading JSON config files, getting the length of an array object within a JSON, or for updating JSON values based on the value's key.
Note: If you are using Automation Anywhere A2019 Community Edition, this package has already been installed for you.
Reference Link: Please find the link to the JSON used in the video here. As is done in the video, you can use a REST Get action and use the provided GitHub URL to fetch the JSON.
- Initialize the Session
- Using the package starts with initializing a session. This means using the initialize action in conjunction with the full JSON (either from the response body of a REST call or after read from a JSON file itself)
- The initialize action validates that the JSON is valid, and will set you up for being able to query the JSON's values.
- Query the JSON
- Using the Query action, users can fill in the key for the value they wish to retrieve.
- The value will be returned in whatever form it exists in the JSON.
- This means if employees is an array, and employees was the value provided as the key for the query action, the entire array of employees would be returned.
- The Query action can also be used for getting the length of an array object. This functionality is especially helpful when looping through the objects in the array is needed.
- Returning the length is done by providing the array key with .length() at the end.
- Example: If employees is the array key, then employees.length() would return the number of objects in the array
- Update the JSON
- The Set action allows you to update the JSON used for the session by providing the defined key as well as the intended paired value.
- Example: If updating the email address for the first employee in the array, the notation would be:
- Key: employees.email
- Value: firstname.lastname@example.org