How To Extract The Data From A JSON – In UiPath

Some business processes may consume the JSON as an input/output to exchange data to/from a web server.

When receiving data from a web server, the data is always a string.

Let’s explore how to extract the field from a JSON string!!!

Example

Implementation using UiPath :

Let us implement a workflow which consumes a JSON string and extracts the required fields.

Step 1:
Drag “Assign” activity into the designer panel and assign some JSON string as shown below.

“{
‘fruit’: ‘Apple’,
‘size’: ‘Large’,
‘color’: ‘Red’
}”

Extract Data from JSON string 1

Step 2:
Drag “Deserialize JSON” activity into the designer panel to deserialize a JSON string. Supply the variable “json_Data” to it as input and create a variable called “out_Json” of JsonObject type.

Extract Data from JSON string 2Extract Data from JSON string 3

Step 3:
Drag “Message Box” activity into the designer panel to display the “Fruit Name”.

Extract Data from JSON string 4.PNG

Similarly, we can extract any number of required fields by passing the names of the appropriate tokens ๐Ÿ™‚

Step 5:
Finally, let’s run the project to display the “Fruit Name”.

Extract Data from JSON string 5.PNG

Click hereย to download the Source Code…

Hope it has helped you…

Advertisements

5 thoughts on “How To Extract The Data From A JSON – In UiPath

  1. Vasundhara

    Hi Sharath, I tried this. It is not working. I am getting this error:- Validation Error: Compiler error(s) encountered processing expression “json_obj.SelectToken(“fruit”)”. Option Strict On disallows implicit conversions from ‘Newtonsoft.Json.Linq.JToken’ to ‘String’. Can you please help?

    1. Vasundhara

      Just had to add .ToString after SelectToken; for eg: json_obj.SelectToken(“fruit”).ToString
      Please update the post ๐Ÿ™‚

      1. Exactly, it works for few activities without .ToString and fails for few ๐Ÿ™‚
        Thanks Vasundhara !!!

  2. I have a field called duration and the output is some number like 80099 (in ms), but i want this number to be number itself and not a string, how to do this??

    1. Hi Vivek
      We have to explicitly convert it to โ€œNumberโ€
      Because the processed output will be a object always:)

      Thanks!!

Leave a Reply

%d bloggers like this: