Hey community!
I have the following payload that I`m receiving as a response:
{
"Messages": [
{
"CreationDate": "2021-09-20T16:09:55.683",
"Code": "100",
"Description": "Document authorized"
},
{
"CreationDate": "2021-09-20T16:09:45.453",
"Code": "904",
"Description": "Document sent"
},
{
"CreationDate": "2021-09-20T16:09:36.03",
"Code": "903",
"Description": "Document accepted"
},
{
"CreationDate": "2021-09-20T16:09:31.123",
"Code": "902",
"Description": "Document validated"
},
{
"CreationDate": "2021-09-20T16:09:24.33",
"Code": "901",
"Description": "Document mapped"
},
{
"CreationDate": "2021-09-20T16:09:17.163",
"Code": "900",
"Description": "Document imported"
}
]
}
What I need to do is, get an array of all the [Messages][Description] items in order to do some assertions. I have tried the following approaches inside the Tests tab:
let response = pm.response.json(),
data = response["Messages"][0]["Description"];
And this:
res.json().Messages[0].Description
However the first one returns me an undefined object, and the second one only returns based on the index provided, which doesn`t work for me, as I could have a variable number of Messages.Description. Is there a way to dynamically create an array?