# How to store a JSON in a variable and use it in the request body?

**URL:** <https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881>\
**Category:** Help Hub\
**Created:** [June 15, 2018, 7:30am UTC](https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881 "2018-06-15T07:30:35Z")\
**Posts on this page:** 2\
**Page:** 3

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [April 16, 2021, 3:15pm UTC](https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881/42 "2021-04-16T15:15:57Z")

</div>

Hi @sonujain , Welcome to the community 🥳

you can try the below snippet:

```auto
    var jsonData = pm.response.json();

pm.environment.set("resp", JSON.stringify(jsonData));
   

//using forEach
_.forEach(jsonData, function(jsonData) {
    if(jsonData.return_code===0)
{
  pm.test('Result has expected properties', function(){
    pm.expect(jsonData).to.have.property('return_code');
    pm.expect(jsonData.return_code).to.eql(0);
  });
}

else if (jsonData.return_code !== 0)
{
        console.error(pm.environment.get('resp'));
}
});

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 25, 2023, 9:57am UTC](https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881/43 "2023-08-25T09:57:56Z")

</div>

Closed on August 25, 2023, 9:57am UTC

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

[Previous page](https://community.postman.com/t/how-to-store-a-json-in-a-variable-and-use-it-in-the-request-body/1881.md?page=2)
