Extract information from Json

Hello,

I have got this Deserialize Json Response and now I want to extract the stats count (236) and the first observationDate (2021-12-15T19:39:30.051Z). I am really grateful for some further help.

{
“results”: [
{
“group”: {
“queueId”: “58c45614-7805-4ee8-917a-3ac4879a959a”,
“mediaType”: “email”
},
“data”: [
{
“metric”: “oWaiting”,
“stats”: {
“count”: 236
},
“truncated”: true,
“observations”: [
{
“observationDate”: “2021-12-15T19:39:30.051Z”,
“conversationId”: “835874ff-917d-44c8-8f4a-218a56ad99c2”,
“sessionId”: “648ab238-f418-469f-bd67-5ac4747def34”,
“requestedRoutingSkillIds”: [
“37c8b7f6-8853-4fee-8700-9af744ce2b64”
],
“routingPriority”: 10,
“participantName”: “John K. Samuel”,
“direction”: “inbound”,
“addressFrom”: “johnksam@kln.gov.my”,
“addressTo”: “partner@zurich.mypurecloud.ie”,
“requestedRoutings”: [
“Bullseye”,
“Standard”
]
},
{
“observationDate”: “2021-12-16T05:11:51.673Z”,
“conversationId”: “0b32e1fe-2353-4431-b755-d1a491712dc8”,
“sessionId”: “3eb4543c-6750-428f-a61d-7ed3874aee84”,
“requestedRoutingSkillIds”: [
“fba57f35-b897-49ee-83e1-f9ef8bab9be8”
],
“requestedLanguageId”: “f8f8339b-b23f-4ea0-a1d9-9e77219cdd54”,
“routingPriority”: 10,
“participantName”: “CHZ_UAT_SCC_Inbound”,
“direction”: “inbound”,
“addressFrom”: “chz.uat.scc.inbound@zurich.ch”,
“addressTo”: “service@zurich.ch”,
“requestedRoutings”: [
“Bullseye”,
“Standard”
]
},
{
“observationDate”: “2021-12-16T05:59:08.649Z”,
“conversationId”: “0aa25128-89d4-47fc-95a9-8e1b0aa20c00”,
“sessionId”: “93f29389-8f0e-4155-affb-afeff75e34a7”,
“requestedRoutingSkillIds”: [
“fba57f35-b897-49ee-83e1-f9ef8bab9be8”
],
“requestedLanguageId”: “f8f8339b-b23f-4ea0-a1d9-9e77219cdd54”,
“routingPriority”: 10,
“participantName”: “Sandro Tedesco”,
“direction”: “inbound”,
“addressFrom”: “tedescosandro@hotmail.com”,
“addressTo”: “service@zurich.ch”,
“requestedRoutings”: [
“Bullseye”,
“Standard”
] }}}

Hi @regina2112

Drag “Deserialize JSON” activity into the designer panel to deserialize a JSON string. Supply a variable to it as input and create an another variable of JsonObject type to use in Output.

image

Use this for reference.

Hope this will be helpful. Thank you.

Hi @Jobin_Joy ,

Thank you for your quick response.

So after I deserialize the Json I want to get the 236 and the first observation date. How would I proceed?

Thank you and best regards,
Regina

HI @regina2112

Please use like this.

LHS: StatCount →
RHS:out_json(“count”).ToString

Later you can convert string to int as below

CInt(StatCount)

Recommended to look into the above mentioned reference, it will give you more idea about this.

Thank you.

Hi @regina2112

  1. Taking the count of the Json.
  2. Use for each Activity (Enumerable.Range 0, Output Count Json)
  3. Use Assign activity
    LHS → String variable
    RHS → “Deserialize JSON Output variable”.GetValue(“observationDate”).ToString

Regards
Gokul

This has not worked. I get “Object reference not set to an instance of an object”

Hey,

jsonObject(“results”)(0)(“data”)(0)(“stats”)(“count”).ToString

jsonObject(“results”)(0)(“data”)(0)(“observations”)(0)(“observationDate”).ToString

where 0 is the iteration of array.

Hi @regina2112

Oops. I didn’t check the data hierarchy,

image

Whatever highlight in yellow is root nodes, marked in red is the key for the value we are looking for.

Can you please try what @pikorpa suggested?

Thank you.


Also have a look on the SelectToken / SelectTokens method like
grafik

1 Like

Thank you very much, now it worked!

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