{
"Test1": {
"label1": "Testing",
"duration": [
{
"Value": "987654",
"Ans": "True"
},
{
"Value": "987159",
"Ans": "True"
}
]
}
}
I want to fetch the value of "Value" and save them with different name in environment. Ex: "987654" saved as result1 and "987159" saved as result2 in environment.
You need to loop through the array of the response body and get it to save each desired item as as unique variable. Based on your requiremments it would be:
var jsonData = pm.response.json();
for (let i = 0; i < jsonData.Test1.duration.length; i++) {
pm.environment.set(
"result" + [i+1], jsonData.Test1.duration[i].Value
)
}
The first block in an array is actually an object value of 0, hence in the function above the loop has to stat with i = 0, however as you wanted the variable to start with integer '1' for the first value required, the name is set as "result" + [i+1] to ensure they are saved with result(n), starting with 'result1' onwards