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);
}

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);

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);
}

Thank you so much vkachineni

This is working

 

Ajay_Chavan
Kilo Sage

please send full json

 

find_real_file.png