Retrieve results from a Json string

Hi Everyone,

Need some help in obtaining the values out of a Json String, below is the string

{
    "Output": [
        {
            "Desc": "**This is a Test Change Request No action is required** HHC Remediation",
            "Display": {
                "display_value": "ft010",
                "link": "https://test/api/now/table/ci/f706f150dbeb09d7c9619a3"
            },
            "start_date": "2022-10-27 02:08:37",
            "description": "**This is a Test Change Request No action is required** \r\nLogin banner will be changed:\r\n\r\nftwlx001\r\nftd002\r\nftwlxhb4\r\n\r\nftw010\r\n",
            "state": "Planning",
            "end_date": "2022-10-31 02:08:43"
        }
    ]
}

I need the below outputs
Desc, display_value, link,start_date, end_date, state, description

Please help.

Thanks

Hi @Dhruvi_Arumugam ,

Have you tried to use Deserialize Json Activity and fetch the required values like below :

jobj("Output")(0)("Desc").ToString

jobj("Output")(0)("Display")("display_value").ToString

jobj("Output")(0)("Display")("link").ToString

jobj("Output")(0)("start_date").ToString

The same method could be used to obtain other key values.
Here, jobj is a Json Object output from Deserialize Json Activity.

Let us know if the methods shown in the visuals help you in achieving your result.

Thanks @supermanPunch for the reply I will try and update you.

Thanks

1 Like

Hi @supermanPunch It is working thanks, can you please explain a bit why you used (0) and this seemed to be JArray to me is it?. Also in case of blank values we will get blank in response?

Thanks!!

@Dhruvi_Arumugam , The Data Output / Input Provided is a Json Object. The Output is a property in it which is a JArray, In this JArray, we only have a Single JObject, Hence the first item access is done by (0).

Yes, The result should be an Empty value, if the values in the Json for the Properties are also blank.

Ok @supermanPunch Thanks.

In some cases like below -

{
    "Output": [
        {
            "Desc": "Crew Hiring Forecast processing for August  has stalled",
            "Display": "",
            "start_date": "",
            "description": "Crew Hiring Forecast processing for August  has stalled at File4",
            "end_date": ""
        }
    ]
}

The display attribute comes empty in case of blank values then if I am using

jobj("Output")(0)("display_value").ToString

It is failing due to attributes missing. Can you please guide handling this scenario?

Thanks

Hi @supermanPunch

Can you guide on this also please.

Thanks!!

@Dhruvi_Arumugam ,

Apologies for the Late response as I was quite busy with other tasks of mine.

I was not able to find a more direct approach of handling the Nested Json values existence. Hence, I Shifted to a method where we can validate that specific nested json keys after performing a conversion to a JObject for that key value (“Display”) and store it in a Dictionary for later access.

Maybe there is a better approach on this, but you could give a try on the below workflow. The workflow also assumes that we have the list of keys already known and only the nested keys to check would be “display_value” and “link”.
Json_ConvertToDictionary.xaml (12.1 KB)

Visuals :
image

Let us know if this works well for your case.

This is currently working fine for me Thanks!!

Thanks

1 Like

HI @supermanPunch

I found one more scenario, in case where the output is coming like this (empty)

{
    "Output": []
}

In this case the code is breaking and I am getting below error on Deserialize Json activity

image

Please help on this also.

Thanks!!

@Dhruvi_Arumugam ,

After the First Deserialization we could check if there are any JArrays present, we could encapsulate the remaining steps within an If Activity where the condition would be as below :

JArray.FromObject(jObj("Output")).Count>0

image

Thanks for the reply, but the bot is failing on the first Deserialize itself refer below ss

Please help

Thanks!

@Dhruvi_Arumugam ,

That would be the Second Deserialize Json Activity. You would need to add steps as explained in the previous post before this Second Deserialize Json Activity.

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