Parse JSON Postman response
You could capture multiple 'name' properties using the _.map()
function of Lodash, which is a built it module on the native application. I've had to modify what you need slightly as the name
key would have been a duplicate.
const result = _.map(pm.response.json().aPIProxy, data => ({
name: data.name,
revisionName: data.revision[0].name
}))
pm.environment.set("response", JSON.stringify(result))
This would then store all the values in an environment variable for you to use elsewhere in another request.
The below postman script might help you.
var jsonData = JSON.parse(responseBody);
var jsonNamesData = jsonData.aPIProxy;
console.log(jsonNamesData);
var parsedData = "";
for(var i=0;i<jsonNamesData.length;i++){
parsedData = parsedData +"\"name\" : \"" +jsonNamesData[i].name+"\", ";
console.log("\"name\" : \"" +jsonNamesData[i].name+"\"");
}
console.log(parsedData);
postman.setEnvironmentVariable("parsedNamesResponse", parsedData); // updating parsed data to the environment variable parsedNamesResponse