# Pass whole object to variable in Collection Runner

**URL:** <https://community.postman.com/t/pass-whole-object-to-variable-in-collection-runner/18589>\
**Category:** Help Hub\
**Tags:** variables, collections, json\
**Created:** [December 20, 2020, 10:49am UTC](https://community.postman.com/t/pass-whole-object-to-variable-in-collection-runner/18589 "2020-12-20T10:49:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hordeous](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hordeous](https://community.postman.com/u/hordeous)\
**Post date:** [December 20, 2020, 10:49am UTC](https://community.postman.com/t/pass-whole-object-to-variable-in-collection-runner/18589/1 "2020-12-20T10:49:30Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/9/a919d0e6098614e9bfdd6c63f50058c1e9b92166.png)  
 ![Collection2](https://us1.discourse-cdn.com/getpostman/original/3X/d/a/daef5c93ab7c732f5841d8e13af8477564ffe306.png)  
But can’t manage to get whole object as variable.  
Any kind of help will be really appreciated.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [December 20, 2020, 11:48am UTC](https://community.postman.com/t/pass-whole-object-to-variable-in-collection-runner/18589/2 "2020-12-20T11:48:52Z")

</div>

> [@hordeous](#):
>
> [  
> {  
> "id:“6464564646”,  
> “name”:“Test”,  
> "Country:“EN”,  
> “some array”:[  
> ]  
> },  
> {  
> "id:“6464564646”,  
> “name”:“Test”,  
> "Country:“EN”,  
> “some array”:[  
> ]  
> },  
> {  
> "id:“6464564646”,  
> “name”:“Test”,  
> "Country:“EN”,  
> “some array”:[  
> ]  
> }  
> ]

```
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}}

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [December 22, 2020, 11:49pm UTC](https://community.postman.com/t/pass-whole-object-to-variable-in-collection-runner/18589/3 "2020-12-22T23:49:20Z")

</div>

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.](https://learning.postman.com/docs/running-collections/working-with-data-files/)  
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 🙂
