# How to save an array of objects?

**URL:** <https://community.postman.com/t/how-to-save-an-array-of-objects/41314>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [November 21, 2022, 12:48pm UTC](https://community.postman.com/t/how-to-save-an-array-of-objects/41314 "2022-11-21T12:48:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyortush\_13](https://avatars.discourse-cdn.com/v4/letter/k/5fc32e/32.png) [@Kyortush\_13](https://community.postman.com/u/Kyortush_13)\
**Post date:** [November 21, 2022, 12:48pm UTC](https://community.postman.com/t/how-to-save-an-array-of-objects/41314/1 "2022-11-21T12:48:16Z")

</div>

How to save an array of objects ?  
To save to environment variable.

The response is:

{“Status”: 1,  
“Message”: “Success”,  
“Code”: 0,

```
"Data": [
    {
        "ID": 100333,
        "Name": "Michael ",
        "Folder": "Folder_1",
        "Is_Available": false
    },
    {
        "ID": 100334,
        "Name": "Lina ",
        "Folder": "Folder_2",
        "Is_Available": false
    },
           {
        "ID": 100335,
        "Name": "Simon ",
        "Folder": "Folder_3",
        "Is_Available": true
    }

```

]  
}

I need to save in the array:

Array\_of\_objects[0] = “ID”: 100333,  
“Name”: "Michael ",  
“Folder”: “Folder\_1”,  
“Is\_Available”: false

Array\_of\_objects[1] = “ID”: 100334,  
“Name”: "Lina ",  
“Folder”: “Folder\_2”,  
“Is\_Available”: false

Array\_of\_objects[2] = “ID”: 100335,  
“Name”: "Simon ",  
“Folder”: “Folder\_3”,  
“Is\_Available”: true  
…

Array\_of\_objects[n] = …

The array length should be unlimited

Thanks!

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [December 6, 2022, 10:22pm UTC](https://community.postman.com/t/how-to-save-an-array-of-objects/41314/2 "2022-12-06T22:22:24Z")

</div>

If I understand your question correctly, you’re trying to save an array to an environment or a variable programmatically.

You can do this within your pre-request or test scripts using [postman scripts](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/). The `pm` object exposes an interface that allows you to `set` or `get` new environments of your choice.

Follow this [guide to learn more](https://learning.postman.com/docs/sending-requests/variables/#defining-variables-in-scripts).

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 7, 2022, 10:57am UTC](https://community.postman.com/t/how-to-save-an-array-of-objects/41314/3 "2022-12-07T10:57:45Z")

</div>

To store and use the arrays as variables you have to JSON.stringify() them before storing, and JSON.parse() them when you retrieve them.

The array appears to be under the data element. Therefore, the following should allow you to store the array.

```auto
pm.environment.set("Data", JSON.stringify(pm.response.json().Data))

```
