# JSON parse error when using a collection variable array as a value of the request body field

**URL:** <https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036>\
**Category:** Help Hub\
**Created:** [December 13, 2022, 7:37pm UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036 "2022-12-13T19:37:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergopergo](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sergopergo](https://community.postman.com/u/sergopergo)\
**Post date:** [December 13, 2022, 7:37pm UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036/1 "2022-12-13T19:37:58Z")

</div>

_My question_: Value of the field “load\_guids” must be an array. I’m using {{reportsLoadGuids}} as a value of the field “load\_guids” but I get a JSON parse error

_Details (like screenshots)_:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/5/85cfa2d043e1846771a264d05fab291fac0aaf32.png)

_I’ve already tried_: tried to cover the variable in brackets (like this [{{reportsLoadGuids}}] ) and discover it (like this {{reportsLoadGuids}} ), the error stays the same

---

<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 14, 2022, 11:05am UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036/2 "2022-12-14T11:05:12Z")

</div>

Drop the square brackets from the body, as it appears you already have these in the variable.

No quotes around the variable name either.

```auto
{
    "customer name": "{{$randomWord}}",
    "load_guids": {{reportsLoadGuids}}
}

```

![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/e/3ef35b021325a4d3a017ad8354d4ff9bb29801b6.png)

![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/a/2a13be1bacbe0a17f4dafb214f0828255f393a9c.png)

---

<div class="post-metadata">

**Author:** ![sergopergo](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sergopergo](https://community.postman.com/u/sergopergo)\
**Post date:** [December 14, 2022, 11:57am UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036/3 "2022-12-14T11:57:02Z")

</div>

Hi, as I’ve written in _I’ve already tried_ section, I’ve tried without brackets in the body, but still get an error, then I noticed on your screenshot how the variable looks like, mine looks different and when I change the variable array by your example everything works fine.  
The problem is that I’m setting an array and adding items to it through another request which creates a single item with this script:

```auto
const first_load_id = jsonData.data.guid;
    var load_guids = pm.collectionVariables.get("reportsLoadGuids");
    var load_guidsA = [load_guids];

    if (load_guidsA == ""){
        pm.collectionVariables.set("reportsLoadGuids", first_load_id)

    }else if (Array.isArray(load_guids) == false){
        load_guidsA.push(first_load_id) &&
        pm.collectionVariables.set("reportsLoadGuids", load_guidsA);

    }else if (Array.isArray(load_guids) == true){
        load_guids.push(first_load_id) &&
        pm.collectionVariables.set("reportsLoadGuids", load_guids);
    }

```

how my variable look like

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/1/7187315d95d1f7c90fb6ae4519ace98175c8c0fb.png)

it works when my variable looks like this

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/2/d27ccad3fa6ee27c5fe539275a6987037b2a6ea4.png)

So the only option is to create an additional for an array and “” for each item?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/0/90abeffdc7d8de78a3560ee91e43cbc656cf9168.png)

As for me, it is strange when you need to edit your code with additional quotes and brackets when the variable already has a valid type

---

<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 15, 2022, 1:31pm UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036/4 "2022-12-15T13:31:29Z")

</div>

From the blurb.

[Using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/#using-variables)

Postman stores variables as strings. If you store objects or arrays, remember to `JSON.stringify()` them before storing, and `JSON.parse()` them when you retrieve them.

---

<div class="post-metadata">

**Author:** ![sergopergo](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sergopergo](https://community.postman.com/u/sergopergo)\
**Post date:** [December 15, 2022, 2:19pm UTC](https://community.postman.com/t/json-parse-error-when-using-a-collection-variable-array-as-a-value-of-the-request-body-field/42036/5 "2022-12-15T14:19:56Z")

</div>

Thanks a lot, your advice worked
