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’
}”
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.
Step 3:
Drag “Message Box” activity into the designer panel to display the “Fruit Name”.
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”.
Click here to download the Source Code…
Hope it has helped you…
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?
Just had to add .ToString after SelectToken; for eg: json_obj.SelectToken(“fruit”).ToString
Please update the post 🙂
Exactly, it works for few activities without .ToString and fails for few 🙂
Thanks Vasundhara !!!
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??
Hi Vivek
We have to explicitly convert it to “Number”
Because the processed output will be a object always:)
Thanks!!