Discussion
Pegasystems Inc.
US
Last activity: 2 Sep 2021 9:54 EDT
RPA JSONUtils -- GetValueFromJSON
I recently had a discussion over how to use the JSONUtils to extract values from a JSON string. This is actually quite easy once you know the format.
Attached is an example for the usage of the JSONUtils with some moderately-complex JSON. You must build the solution before opening the automations as the extension needs to be compiled for the method to exist. Once you have extracted and are ready to look at the solution, build it first before opening any of the components to avoid any errors.
In order for the JSONUtils component’s GetValueFromJSON method to work, it must have a root node of some kind rather than start directly from an array. To facilitate this, we’ve created a type extension for the component that adds a method checking to see if the JSON starts with a {. If it does, then that string is used as the JSON and evaluated. If it does not, then a root node is added to the JSON as well as the appropriate surrounding brackets.
Once the JSON is formatted, the GetValueFromJSON method of the component works as expected. The format of the key uses standard JSON formatting. In this case we use, root[index of the root object since it is a list].whatever object you want under the root[required if the object is a collection where this would be the index of that collection].key you want
Have a look at the attached solution and let me know if you have any questions.
Thank you to Jeff Badger and Damien Renier for the assistance.