Need to Read JSON data and display last name of the employee

Read JSON data and display last name of the employee whose ID is “2” in a message box.

  1. {
  2. “employee”: [
  3.   { 
    
  4.      "id":”1”, 
    
  5.     "name": "Tom", 
    
  6.     "lastname": "Prince" 
    
  7.  }, 
    
  8.  { 
    
  9.     "id":"2", 
    
  10.     "name": "Nick", 
    
  11.     "lastname": "Johnson" 
    
  12.  } 
    
  13. ]
  14. }

Please help me to create a workflow on this from end to end

Hi

Welcome to uipath forum

Use the deserialise Json array activity

For that go to design tab → manage packages → all packages → search for UiPath.web.Activity and install it

And steps involved are as follows

  1. Read the string input and save it in a variable named Strinput

  2. Then use a DESERIALISE JSON activity and pass the above string variable as input and type argument will be Newtonsoft.Json.LinqJObject result of this activity will be jsonobject

  3. Use a assign activity like this

Jsonstring = jsonobject(“employee”).ToString

  1. Then Use Deserialize Json Array activity with Type Argument and pass the Jsonstring in input and say the output of this activity will be Jsonarray
  1. Now use a FOR EACH activity and pass the above variable Jsonarray and change the type argument as Newtonsoft.Json.LinqJObject

  2. Inside the loop use a IF condition like this

item(“id”).ToString.Contains(“2”)

If true it will go to then block where use a assign activity like this

str_output = item(“lastname”).ToString

In fact we have got examples on how to use those two deserialise activity in that doc itself
Please refer that for more details

Cheers @S_S_Kumar

1 Like

As an alternate we can filter to the person directly without for each:

Variables:
grafik

Flow:

Find starter help here:
ppr_JSONBox_SSKumar.xaml (6.8 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.