Parse required data from API response

studio
api
web

#1

I have a API response in Newtonsoft.Json.Linq.JArray, I need to get a few set of data from the response rendered. Can anyone help me.

Regards
Harsh


#2

This returns value of specified key in JSON : JArray.Selecttoken(“Json Key”)


#3

Thanks

Which activity do i need to use?


#4

@Harsh_Dixit, Use Assign activity to get the value some string variable = JArray.Selecttoken(“Json Key”).tostring

Regards,
Dominic


#5

I have tried it but its not working


#6

@Harsh_Dixit,
Can you share your screenshot / Xaml to have a detailed idea ?


#7

The system is allowing me to upload any document.

Let me explain

I have a API response in json which I have successfully parsed using deserialized activity. JSON given below -
[
{
“status”: 1,
“statusStr”: “Critical”,
“entity”: “4_CPUUSAGE”,
“severity”: " Critical",
“who”: “Unacknowledge”,
“message”: “CPU Utilization is 52%, threshold value for this monitor is 50%: Top 3 Processes:-svchost#19 - 51.717%;WmiPrvSE#1 - 1.398%;WmiPrvSE#2 - 1.398%”,
“modTime”: “20 Sep 2017 01:35:36 PM IST”,
“category”: “Desktop”,
“numericSeverity”: 1,
“deviceName”: “in2-noisr-svn1.in2ittech.local”,
“severityString”: “Critical”,
“displayName”: “In2-noisr-svn1”,
“modTimeLong”: 1505894736223,
“statusNum”: 1
},
{
“status”: 2,
“statusStr”: “Trouble”,
“entity”: “6_DiskUtilization”,
“severity”: " Trouble",
“who”: “Unacknowledge”,
“message”: “Disk Utilization is 41%, threshold value for this monitor is 40%”,
“modTime”: “20 Sep 2017 12:15:39 PM IST”,
“category”: “Desktop”,
“numericSeverity”: 2,
“deviceName”: “in2-noisr-svn1.in2ittech.local”,
“severityString”: “Trouble”,
“displayName”: “In2-noisr-svn1”,
“modTimeLong”: 1505889939761,
“statusNum”: 2
}
]

Now I want the following fields in to be consumed by another API -
modTime
deviceName
displayName
entity

Can you help me achieve the same.


#8

@Harsh_Dixit, Now i understood the problem, whatever you have attached below,

[
{
“status”: 1,
“statusStr”: “Critical”,
“entity”: “4_CPUUSAGE”,
“severity”: " Critical",
“who”: “Unacknowledge”,
“message”: “CPU Utilization is 52%, threshold value for this monitor is 50%: Top 3 Processes:-svchost#19 - 51.717%;WmiPrvSE#1 - 1.398%;WmiPrvSE#2 - 1.398%”,
“modTime”: “20 Sep 2017 01:35:36 PM IST”,
“category”: “Desktop”,
“numericSeverity”: 1,
“deviceName”: “in2-noisr-svn1.in2ittech.local”,
“severityString”: “Critical”,
“displayName”: “In2-noisr-svn1”,
“modTimeLong”: 1505894736223,
“statusNum”: 1
},
{
“status”: 2,
“statusStr”: “Trouble”,
“entity”: “6_DiskUtilization”,
“severity”: " Trouble",
“who”: “Unacknowledge”,
“message”: “Disk Utilization is 41%, threshold value for this monitor is 40%”,
“modTime”: “20 Sep 2017 12:15:39 PM IST”,
“category”: “Desktop”,
“numericSeverity”: 2,
“deviceName”: “in2-noisr-svn1.in2ittech.local”,
“severityString”: “Trouble”,
“displayName”: “In2-noisr-svn1”,
“modTimeLong”: 1505889939761,
“statusNum”: 2
}
]

  1. Note : above values will be enclosed within a key (here Say ‘Values’).
  2. Convert the entire string content to Jobject as follows:
    Jobject J1= Jobject.Parse(str)
  3. Loop through For each item in J1.SelectToken(“Values”)
  4. This item contains values for each nodes inside { }. first Time if you access using item.SelectToken(“status”) (inside for each) you will get ‘1’ and very next time you get ‘2’

Syntax:

foreach( Jobject item in J1.SelectToken(“Values”) )
{
string statusVal= item.SelectToken(“status”);
}


#9

Yes, JObject works when we use variable name “jobject” and variable type jobject with Default value to “new jobject” then parse will work


#10

Hi @Dominic

Can you please share the workflow of your suggested way?

Thanks.


#11

Hello attached jobject sample workflowJobject.xaml (6.5 KB)

Use Jobject variable as new Jobject and parse string.