Save into variable a Json value from response and that is stored inside an object

On the response body, inside an object there is a value (name) that i need to convert into variable. Response goes like this;

“timestamp”: “20/07/2022 13:35:23”,
“status”: 200,
“description”: “OK”,
“message”: “XXXXXX”,
“requestId”: “XXXXXXXXXXXXXXX”,
“data”: [
{
“name”: “XXXXXX”,
“tenant”: “XXXXX”,
“vcenteruuid”: “XXXXXXXXXX”,
“vmOwner”: “XXXXXXXXX”,
“creationDate_utc”: “XXXXXXX”,
“deleteDate_utc”: null,
“archiveDate_utc”: null,
“currentStatus”: 1,
“requestStatus”: null,
“assetId”: null,
“serviceClass”: “Bronze”,
“clusterType”: “Multicluster”,
“description”: “XXXXXXX”,
“serviceIp”: “XXXXXXXXX”,
“adminIp”: “XXXXXX”,
“az”: “XX”,
“environment”: “DEV”,
“os”: “XXXXXXXXX)”,
“cpu”: “X”,
“memory”: “XXXXXXX”,
“storage”: “XXXXXX”,
“networkZone”: “XXXXX”,
“commitmentPeriod”: “XXXXXXXX”,
“businessService”: “XXXXXX”,
“availabilitySet”: null,
“origin”: “green”,
“vcenterUrl”: “XXXXXXXXXX”,
“customTags”: null
}

Since “name” is to be found inside “Data” object i don´t know how to interact with it and store it into a variable.

Im very new into this; regards

Hi @ibragroupsantander

You would need to specify the ‘data’ array index.

Try this;

const response = pm.response.json();
console.log(response.data[0].name);

If you need ‘name’ from more than just the first index then you would likely need to build it into a for loop to cycle through the entire array.

1 Like

it worked!!!; thank you so much!!!