I have API output i need to get particular value from the text and write it in a excel

{
“page”: 1,
“per_page”: 6,
“total”: 12,
“total_pages”: 2,
“data”: [
{
“id”: 1,
“email”: “george.bluth@reqres.in”,
“first_name”: “George”,
“last_name”: “Bluth”,
“avatar”: “https://reqres.in/img/faces/1-image.jpg
},
{
“id”: 2,
“email”: “janet.weaver@reqres.in”,
“first_name”: “Janet”,
“last_name”: “Weaver”,
“avatar”: “https://reqres.in/img/faces/2-image.jpg
},

for the output I need to get the value of ID ,email,lastname,firstname
ID =1
first name = janet

Hi @sathish27 first deserialize the json and then

JsonObjVar(“data”)(0)(“id”).ToString
JsonObjVar(“email”)(0)(“email”).ToString

like this you can get your values.

You can use a combination of foreach + SelectToken, to obtain your results:

*I had to fix the json, since it is invalid as you copied it to the message:

image
FixedJson.txt (384 Bytes)

image

Steps:
1- Get Json as string from HTTP Results
2- Deserialize Json using the activity from UiPath.WebApi.Activities
3- For each JObject in var_des_Json.SelectToken("$.data")
4- inside the for each, you can obtain your data with the following 2 selectToken functions:

get ID:

item.selectToken("$.id").ToString

get First Name:

item.selectToken("$.first_name").ToString
1 Like

after fixing the jSON by adding a proper ending:

we used deserialize JSON activity - out: myJObject

we can create a list of Dictionaries by:


myJObject("data").ToObject(Of List(Of Dictionary(Of String, String)))
and can then easy access the different user info e.g.

1 Like

Hi @sathish27 ,

Maybe we could convert the data directly to Datatable , if the requirement is the same ?

After the Deserialization of the Output response to a Json Object, we could get the Data as value and Convert the value to a Datatable.
image

Json Data :
image

Conversion to Datatable :
image

Expression :

Newtonsoft.Json.JsonConvert.DeserializeObject(Of System.Data.DataTable)(strJson("data").ToString)

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