# How to get an array of a nested JSON response

**URL:** <https://community.postman.com/t/how-to-get-an-array-of-a-nested-json-response/28008>\
**Category:** Help Hub\
**Tags:** tests, collections, json, response, array\
**Created:** [September 20, 2021, 9:26pm UTC](https://community.postman.com/t/how-to-get-an-array-of-a-nested-json-response/28008 "2021-09-20T21:26:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe.pazinatto](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@felipe.pazinatto](https://community.postman.com/u/felipe.pazinatto)\
**Post date:** [September 20, 2021, 9:26pm UTC](https://community.postman.com/t/how-to-get-an-array-of-a-nested-json-response/28008/1 "2021-09-20T21:26:15Z")

</div>

Hey community!

I have the following payload that I`m receiving as a response:

```auto
{
    "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:

```auto
let response = pm.response.json(),

data = response["Messages"][0]["Description"];

```

And this:

```auto
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?

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [September 20, 2021, 11:44pm UTC](https://community.postman.com/t/how-to-get-an-array-of-a-nested-json-response/28008/2 "2021-09-20T23:44:00Z")

</div>

```
    Description = response.messages.map( (item)=>item.description)

```

Use array Map function , 😌🎉

---

<div class="post-metadata">

**Author:** ![felipe.pazinatto](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@felipe.pazinatto](https://community.postman.com/u/felipe.pazinatto)\
**Post date:** [September 21, 2021, 3:01pm UTC](https://community.postman.com/t/how-to-get-an-array-of-a-nested-json-response/28008/3 "2021-09-21T15:01:13Z")

</div>

Thanks @praveendvd for the solution!
