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

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):

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

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

No quotes around the variable name either.

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



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:

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

it works when my variable looks like this

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

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

From the blurb.

Using variables | Postman Learning Center

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.

1 Like

Thanks a lot, your advice worked