I am using an API to get a result in JSON. I want to get a particular element from that JSON output (say name). Can somebody please help me with all the steps required? using API calling for the first time

I am using an API to get a result in JSON. I want to get a particular element from that JSON output (say name). Can somebody please help me with all the steps required? using API calling for the first time.

This is the JSON Format. I want to fetch sap_cost_center from this.
Please help…

{
“meta”: {
“filter”: “grid_company_account=24056310”,
“page_size”: 30,
“page_number”: 1,
“sort”: “id”,
“size”: 1
},
“data”:
{
“type”: “legal_information_of_sites”,
“id”: 91787,
“attributes”: {
“grid_company”: 63386,
“site_id”: 135636,
“grid_company_account”: “24056310”,
“sap_cost_center”: “CTO08007”,
“id”: 91787
}
}
,
“included”: [*],
“user”: {
“options”: {}
}
}

@Pankit

Check this out

(Newtonsoft.Json.JsonConvert.DeserializeObject(of jobject)(JsonString)(“data”)(“attributes”)(“sap_cost_center”)).tostring

Import namespace Newtonsoft.Json in Imports Section

1 Like

Capture88

@Pankit

Are you using the same Json string and Query mentioned above ? is it possible to share the workflow, (or screenshots would do)

1 Like

Have you tried this,

Here is the screenshot of getting ID inside the data > attributes > id …

You can get anything in this way

1 Like

{
“meta”: {
“filter”: “grid_company_account=24056310”,
“page_size”: 30,
“page_number”: 1,
“sort”: “id”,
“size”: 1
},
“data”: [
{
“type”: “legal_information_of_sites”,
“id”: 91787,
“attributes”: {
“grid_company”: 63386,
“site_id”: 135636,
“grid_company_account”: “24056310”,
“sap_cost_center”: “CTO08007”,
“id”: 91787
}
}
],
“included”: ,
“user”: {
“options”: {}
}
}

Can you please check this? Updated one

{
“meta”: {
“filter”: “grid_company_account=24056310”,
“page_size”: 30,
“page_number”: 1,
“sort”: “id”,
“size”: 1
},
“data”: [
{
“type”: “legal_information_of_sites”,
“id”: 91787,
“attributes”: {
“grid_company”: 63386,
“site_id”: 135636,
“grid_company_account”: “24056310”,
“sap_cost_center”: “CTO08007”,
“id”: 91787
}
}
],
“included”: ,
“user”: {
“options”: {}
}
}

Can you tell me which tag exactly you want? so that I Can build and forward you

1 Like

The one I shared now… It has data arranged in some array, I guess… Thats what I didnt notice earlier… Getting an error because of it

Check this @Pankit , it should work and I hope it is very easy to understand…
Json to get ID.zip (2.3 KB)

As we have arrays inside the JSON data, we need to pass the root element which the array contains and deserialize the array. Then we have to give the index of the array (The activity doesn’t know if there is only one or more arrays present in the string) .
If you have any doubts, let me know.

2 Likes

thank you so much Hareesh! It worked… :slight_smile: :slight_smile:

Glad to help @Pankit… :slight_smile:

1 Like

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