sathish27
(sathish uipath)
October 20, 2022, 10:04am
1
{
“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:
FixedJson.txt (384 Bytes)
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
ppr
(Peter)
October 20, 2022, 10:35am
4
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.
Json Data :
Conversion to Datatable :
Expression :
Newtonsoft.Json.JsonConvert.DeserializeObject(Of System.Data.DataTable)(strJson("data").ToString)
system
(system)
Closed
October 26, 2022, 11:35am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.