Reading JSON Payload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 12:32 AM
Hi Team,
We are performing an integration between Nexthink and ServiceNow. The below is the payload we are getting from Nexthink.
{
"queryId": "#devices_with_frustating_user_experience",
"executedQuery": "devices| include dex.scores during past 24h| compute device_performance_score_per_user = endpoint.device_performance_value.avg()| where device_performance_score_per_user <= 30| list name, login.last_login_user_name, last_seen, hardware.type, entity,operating_system.name, device_performance_score_per_user",
"rows": 1000,
"executionDateTime": {
"year": 2024,
"month": 6,
"day": 13,
"hour": 14,
"minute": 22,
"second": 12
},
"headers": [
"device.name",
"device.login.last_login_user_name",
"device.last_seen",
"device.hardware.type",
"device.entity",
"device.operating_system.name",
"device_performance_score_per_user"
],
"data": [
[
"ROL013886",
"sgageatu@ACE",
"2024-06-13 14:13:53",
"laptop",
"Romania",
"Windows 10 Enterprise 22H2 (64 bits)",
0
],
[
"PLD131322",
"lboncal@ACE",
"2024-06-13 14:13:40",
"desktop",
"Poland",
"Windows 10 Enterprise 22H2 (64 bits)",
0
],
[
"PLL017004",
"bleszczynski@ACE",
"2024-06-13 14:13:54",
"laptop",
"Poland",
"Windows 10 Enterprise 22H2 (64 bits)",
0
]
]
}
Can you please help me how to read the data ? firstly is the data valid JSON
Regards
B Siva Teja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 12:48 AM
Hi @Ballela Siva Te ,
To answer your queries.
Firstly, YES it a valid JSON.
It could be hard to use read the json in text format, you can use online JSON viewers they format you JSON in much readable manner, and they verify it's validity as well.
you can find multiple json viewers online, one of them is : https://jsonformatter.org/json-viewer
Secondly, How to use it.
1) Parse and store it in a variable.
var response = JSON.parse('your_string_json_response');
2) Then you can use dot walking and access the values of the response.
ie.. response.queryId;
response.rows;
To learn more about JSON, you can refer : https://www.w3schools.com/js/js_json.asp
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 12:56 AM
Thanks for your response, How can I establish the relation between headers and data.
Please suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 02:04 AM
I believe you mean "key" and you mention "header". So JSON is a combination or key and values.
Once you open the json response in a json viewer it will show you how the json is structured, you can close and expand each node, and see the encapsulated data inside. That will help you dotwalk and reach the data you need.
Once you dot walk to a key, it gives you the value.
example: response.headers[0] will give you => device.name
response.queryId will give you => #devices_with_frustating_user_experience
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.