0

I am using the below code for REST OUTBOUND call and this is working as expected. but i am trying to parse the second response body but i am unable to retrieve the values under objects.

try { 
 var r = new sn_ws.RESTMessageV2('test', 'post');

 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
 gs.print(response.getBody());
 gs.print(response.getStatusCode());
 var JsonObject = JSON.parse(responseBody);
 var sid = JsonObject.sid; 
 gs.print(sid);

 var r1 = new sn_ws.RESTMessageV2('x_257605_test.gateways', 'POST' );
 r1.setRequestHeader("X-chkp-sid",sid );
 var response1 = r1.execute();
 var responseBody1 = response1.getBody();
 var httpStatus = response1.getStatusCode()
 gs.print(response1.getBody());
 var JsonObject1 = JSON.parse(responseBody1);
 gs.print(JsonObject1.objects.uid);
}
catch(ex) {
 var message = ex.message;
}

please see the sample json response and i need to extract the values under objects like uid/name/cluster-member-names

mikegray.397
  • 75
  • 1
  • 2
  • 9

1 Answers1

0

the objects property is an array of objects. This line should change from:

gs.print(JsonObject1.objects.uid);

to:

gs.print(JsonObject1.objects[0].uid);

To grab data from the first object's properties, or your could iterate over them if you need to perform an operation on all the objects returned.