Array is returned as comma separated string instead of array

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”

Hey @cryosat-participan11 :wave:

Welcome to the Postman Community! :postman:

You would probably need to use JSON.stringify here:

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

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

“ambiances_list”: {{ambiances}}

Thanks, this solved the problem

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