Parse Nested JSON Array and objects

triciav
Kilo Sage

I have a RestMessage that I am getting back the JSON as below,

How do I parse this to get the SerialNumbers?

Thank you

find_real_file.png

{
"Devices":[
{
"EasIds":{
"EasId":[
"XXPI8PIKDD4LP5ID797BVKSGKO",
"XXFDA7DB295B406C9933FA634B190B77"
]
},
"Udid":"00000000-000A6C940E30802E",
"SerialNumber":"xxxxxxxxx",

1 ACCEPTED SOLUTION

your obj is the data

//try the following code

 

var json = new global.JSON();
var obj = json.decode(responseBody);
gs.info("TRICIA Json " + obj.Devices[0].SerialNumber);
for(i = 0; i<= obj.Devices.length-1; i++)
{
gs.info(obj.Devices[i].SerialNumber);
}

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

10 REPLIES 10

 

var data = {}; //your json

var serial = [];
for(i = 0; i<= data.Devices.length-1; i++)
{
serial.push(data.Devices[i].SerialNumber);

}
console.log(serial);
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

What do you mean by this?

var data = {}; //your json

This is my code

var json = new global.JSON();
var obj = json.decode(responseBody);
gs.info("TRICIA Json " + obj.Devices[0].SerialNumber);
var data = {obj}; //your json

for(i = 0; i<= data.Devices.length-1; i++)
{
gs.info(data.Devices[i].SerialNumber);
}

your obj is the data

//try the following code

 

var json = new global.JSON();
var obj = json.decode(responseBody);
gs.info("TRICIA Json " + obj.Devices[0].SerialNumber);
for(i = 0; i<= obj.Devices.length-1; i++)
{
gs.info(obj.Devices[i].SerialNumber);
}

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Thank you so much vkachineni

This is working

 

Ajay_Chavan
Kilo Sage

please send full json

 

find_real_file.png

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****