# Array is returned as comma separated string instead of array

**URL:** <https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747>\
**Category:** Help Hub\
**Tags:** variables, array\
**Created:** [January 19, 2024, 2:52pm UTC](https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747 "2024-01-19T14:52:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonatiuhromero](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tonatiuhromero/32/28496_2.png) [@tonatiuhromero](https://community.postman.com/u/tonatiuhromero)\
**Post date:** [January 19, 2024, 2:52pm UTC](https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747/1 "2024-01-19T14:52:15Z")

</div>

I am trying to create request with a Pre-request script where I have an array. Then I am trying to use that array in a request. When I use the variable reference I get the array as a comma separated string of the elements. How can I get the array correctly?

Example: Pre-request script

ambiances = [“FAMILY\_KIDS\_FRIENDLY”, “TRADITIONAL”, “MODERN”, “ROMANTIC”]  
pm.environment.set(“ambiances”, ambiances)

Body:  
“ambiances\_list”: “{{ambiances}}”

Console:

console.log(pm.environment.get(‘ambiances’)) :  
(2) [true, false]

1. 0: true
2. 1: false

console.log(pm.environment.replaceIn(‘{{ambiances}}’)):  
“true,false”

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 19, 2024, 3:01pm UTC](https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747/2 "2024-01-19T15:01:45Z")

</div>

Hey @tonatiuhromero 👋

Welcome to the Postman Community! :postman:

> [@tonatiuhromero](#):
>
> pm.environment.set(“ambiances”, ambiances)

You would probably need to use `JSON.stringify` here:

```javascript
pm.environment.set(“ambiances”, JSON.stringify(ambiances));

```

And then in the body, you should remove the quotes around the variable syntax:

```auto
“ambiances_list”: {{ambiances}}

```

---

<div class="post-metadata">

**Author:** ![tonatiuhromero](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tonatiuhromero/32/28496_2.png) [@tonatiuhromero](https://community.postman.com/u/tonatiuhromero)\
**Post date:** [February 2, 2024, 3:03pm UTC](https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747/3 "2024-02-02T15:03:36Z")

</div>

Thanks, this solved the problem

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [February 5, 2024, 3:04pm UTC](https://community.postman.com/t/array-is-returned-as-comma-separated-string-instead-of-array/56747/4 "2024-02-05T15:04:13Z")

</div>

Closed on February 5, 2024, 3:04pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
