I have this JSON Response from API call
[
{
"id": 20599,
"name": "Deliver",
"options": [
{
"id": 63775,
"name": "Item",
"dataType": "SelectMultiOption",
"required": false,
"options": [
{
"id": 426,
"name": "Towels"
},
{
"id": 427,
"name": "Toothbrush"
},
{
"id": 428,
"name": "Pillow"
}
]
}
]
}
]
I am using this code to get the id of the service "Deliver"
var data = JSON.parse(responseBody);
var loop_count = 0
for (count = 0; count < data.length; count++)
{
if (data[count].name == "Deliver")
{
var job_id = data[count].id;
postman.setEnvironmentVariable("service_id", job_id);
}
}
The questions are:
- How can I get value from array "options", I need to get the "id": 63775 and store as "item_id" and the "name":"Item" as "item_name" postman variables.
- Then I need to select the "options" nested in record "Item" and select the option "name": "Toothbrush" and store in postman variable "svc_optn_optn_name" and it's "id" stored in "svc_optn_optn_id"