Reading JSON payload

Ballela Siva Te
Tera Contributor

Hi Team,

 

we are tasked with reading a payload which is given below. Please help me reading the payload which helps me in performing an integration

 

{
"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
],
[
"PLL014089",
"kbulinski@ACE",
"2024-06-13 14:13:54",
"laptop",
"Poland",
"Windows 10 Enterprise 22H2 (64 bits)",
0
]

}

2 REPLIES 2

Krushna R Birla
Kilo Sage

Hi @Ballela Siva Te 

 

Please refer below payload, which helps you here. I have added comments which explain what that line means

 

 

{
  "queryId": "#devices_with_frustating_user_experience", // Query identifier
  "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", // Executed query string
  "rows": 1000, // Number of rows returned
  "executionDateTime": { // Query execution date and time
    "year": 2024,
    "month": 6,
    "day": 13,
    "hour": 14,
    "minute": 22,
    "second": 12
  },
  "headers": [ // Column names for the data
    "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": [ // Data rows
    [
      "ROL013886", // Device name
      "sgageatu@ACE", // Last login user
      "2024-06-13 14:13:53", // Last seen time
      "laptop", // Hardware type
      "Romania", // Entity/location
      "Windows 10 Enterprise 22H2 (64 bits)", // Operating system
      0 // Device performance score per user
    ],
    [
      "PLD131322",
      "lboncal@ACE",
      "2024-06-13 14:13:40",
      "desktop",
      "Poland",
      "Windows 10 Enterprise 22H2 (64 bits)",
      0
    ],
    [
      "PLL014089",
      "kbulinski@ACE",
      "2024-06-13 14:13:54",
      "laptop",
      "Poland",
      "Windows 10 Enterprise 22H2 (64 bits)",
      0
    ]
  ]
}

 

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Sandeep Rajput
Tera Patron
Tera Patron

@Ballela Siva Te You can use the following code inside a background script and your see the way how the JSON response is converted to an object from the string and various elements are accessed from it.

 

var jsonString = '{ "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 ], [ "PLL014089", "kbulinski@ACE", "2024-06-13 14:13:54", "laptop", "Poland", "Windows 10 Enterprise 22H2 (64 bits)", 0 ]] }';
var jsonObj = JSON.parse(jsonString);
gs.info(jsonObj.queryId); //Prints queryid
gs.info(jsonObj.executedQuery); //Prints executedQuery
gs.info(jsonObj.headers[0]); //Prints object at 0th index of headers arrary

 

Please mark the response helpful and accepted solution if it manages to address your question.