Extract value from http response

Hi,

I am working on http call (API) and getting below sample response.
{
“ObjectA”: {
“Name”: “Fruit”,
“Color”: “Red”
},
“contains”: [
{
“FruitName”: “Mango”,
“IsFound”: “Yes”
}
]
}

Now I have to check the Condition if IsFound is Yes, then I have to extract FruitName as Mango.

Any help is greatly appreciated.

Thanks in advance.

1 Like

You need to de-serialize it first then get the element root for ‘contains’ from the xdoc

Xdoc.Root.Descendants(XNameSpace+ “contains”)

then access the IsFound element within that by de-serializing that into a new xdoc:

xdocContains.Root.Descendants(XNameSpace+ “IsFound”).value.tostring

Hi TimK,

Thanks, but how can I get XnsGCNS?
My requirement is to extract FruitName if IsFound equals to Yes.

Hi,

Can you try the following?

  1. First, Deserialize your string using Deserialize Json activity in Web Activity Package.
  2. Then you can get JObject variable (Let’s say jo).
  3. Next you can get JToken variable (say jt) like jt=jo("contains")
  4. Finally, you can get each value as jt.First.Item("FruitName") and jt.First.Item("FruitName")

Regards,

2 Likes

Sorry XnsGCNS is just an argument name - Xns - is the XNamespace (This is probably isnt required.)

Take a look at this link :slight_smile:

Hi Yoichi,

Thanks. It is very much useful.

If it has multiple nodes with different IsFound, then it is a problem. For example,

{
“ObjectA”: {
“Name”: “Fruit”,
“Color”: “Red”
},
“contains”: [
{
“FruitName”: “Mango”,
“IsFound”: “Yes”
},
{
“FruitName”: “Banana”,
“IsFound”: “No”
},
{
“FruitName”: “Apple”,
“IsFound”: “Yes”
},
{
“FruitName”: “Grapes”,
“IsFound”: “Yes”
}
]
}

In this case, I have to get Mango, Apple and Grapes

Thanks in advance.

Hi,

It would be like the following image.

sample20191203.xaml (6.3 KB)

2 Likes

Check this @chandrasekhar.jella

jsondata.xaml (6.0 KB)

You can check for the name of the fruit to get the value and get the required value of flag

Hi Yoichi,

Thanks for sharing logic and it’s working.

1 Like

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