Pass whole object to variable in Collection Runner

Hello everyone
I’m having a problem passing whole to object to variable then use it as a body in call.
Here is how my data looks like:
[
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
},
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
},
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
}
]

On request body i managed get some values from iteration.



But can’t manage to get whole object as variable.
Any kind of help will be really appreciated.

pm.environment.set("varaible",[
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
},
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
},
{
"id:“6464564646”,
“name”:“Test”,
"Country:“EN”,
“some array”:[
]
}
]

)

you can use pm.environment.set to properly add javascript objects to the variable.

now the environment variable named “variable” will have your json object and can be accessed as {{variable}}

Hi!
I understand you are reading a data file to runner and trying to access each object as a variable.
Current format of the data file only allows you to access "id“, “name”, “Country”, “some array”, i.e. the keys of each object, via iterationData.get() method.
If you want to make each object accessible by a variable, you would need to something like:

const User = function (id, email, name) {
this.id = id
this.email = email
this.name = name
}

const id = pm.iterationData.get(‘id’)
const email = pm.iterationData.get(‘email’)
const name = pm.iterationData.get(‘name’)

const myUser = new User(id, email, name)

pm.variables.set(‘myUser’, myUser)

Hope this helps :slightly_smiling_face: