1

JSON Response as below:

{ "value":[ { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" } ] }

Tried below code snippet:

const responseBody = '{ "value":[ { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" } ] }';
var data = JSON.parse(responseBody);
const temp = [];
data.forEach(function(value, i){
if(data.value[i]){
temp[i] = data.value[i].email
}
});
var subscriptions = temp.join(",");
postman.setEnvironmentVariable("testData", temp);

0

1 Answer 1

2

data is an object, not an array. It doesn't have a forEach method. You have to iterate over data.value:

const responseBody = '{ "value":[ { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" }, { "email": "[email protected]" } ] }';
var data = JSON.parse(responseBody);
const temp = data.value.map(value => value?.email);
var subscriptions = temp.join(",");
console.log(subscriptions);
//postman.setEnvironmentVariable("testData", temp);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.