# Add Json stored in a variable to a request body

**URL:** <https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582>\
**Category:** Help Hub\
**Tags:** json\
**Created:** [May 9, 2018, 11:10am UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582 "2018-05-09T11:10:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NRS](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/nrs/32/586_2.png) [@NRS](https://community.postman.com/u/NRS)\
**Post date:** [May 9, 2018, 11:10am UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582/1 "2018-05-09T11:10:32Z")

</div>

Hi all!

I been trying to find a way to store a json in a variable in a GET request, store it in a collection variable and use it in a POST request in a collection run.  
So far, I been able to store it with no issues in the GET request, but having issues to post it correctly.

I tried using:  
“{{MyJsonVar}}”, [{{MyJsonVar}}], [“{{MyJsonVar}}”], {{MyJsonVar}} and still no luck. Is there anything I’m missing? Any help would be greatly appreciated!

Cheers!

---

<div class="post-metadata">

**Author:** ![kunagpal](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kunagpal/32/9_2.png) [@kunagpal](https://community.postman.com/u/kunagpal)\
**Post date:** [May 9, 2018, 11:14am UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582/2 "2018-05-09T11:14:49Z")

</div>

Hey @NRS, could you share more details on the exact structure of your requests and json value? Feel free to redact sensitive information 😄

---

<div class="post-metadata">

**Author:** ![NRS](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/nrs/32/586_2.png) [@NRS](https://community.postman.com/u/NRS)\
**Post date:** [May 9, 2018, 12:58pm UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582/3 "2018-05-09T12:58:03Z")

</div>

Yes of course! So the structure goes like this:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/3/53e150ffb50f6a93985b826dbd1ccf20773e0fa4.png)

**The GET request have this in the tests:**

```auto
try{
    // parse Json response object
    let result = JSON.parse(responseBody);
    
    let existingJobId = result.id;
    
    let customFields = result.properties;
    console.log('Original Job bag custom fields: ' + customFields);
    let stringifiedCustomFields = JSON.stringify(customFields);
    console.log('stringified custom fields: ' + stringifiedCustomFields);
    
    // make sure we clean up any previous values.
    pm.variables.unset("properties");
    
    tests["Job Bag Exists"] = existingJobId !== null;
    tests["Has custom fields"] = customFields !== null;
    
    pm.variables.set("job_id", existingJobId);
    pm.variables.set("properties", stringifiedCustomFields);

    }catch(e){
        console.log('Error parsing JSON: ' + e);
    }
    
    postman.setNextRequest('DuplicateJobBag');

```

Then in the POST body, I have this:

```auto
{
	"CopyFromId": {{job_id}},
	"Name": "{{next_job_name}}",
	"CompletionDate": "02/02/2011",
	"Properties": "{{properties}}"
}

```

properties is a variable in the collection and is the JSON i need to send in the duplicate request.  
Sadly, is sending that as null.

Cheers!

---

<div class="post-metadata">

**Author:** ![oskarkaminski.dev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/oskarkaminski.dev/32/3574_2.png) [@oskarkaminski.dev](https://community.postman.com/u/oskarkaminski.dev)\
**Post date:** [February 13, 2020, 10:07am UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582/4 "2020-02-13T10:07:02Z")

</div>

@kunagpal I must say I’m a bit surprised what I see.  
Have you marked @NRS 's description of a problem as a solution to the problem? 😃

---

<div class="post-metadata">

**Author:** ![hypo](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@hypo](https://community.postman.com/u/hypo)\
**Post date:** [January 17, 2022, 9:26am UTC](https://community.postman.com/t/add-json-stored-in-a-variable-to-a-request-body/1582/5 "2022-01-17T09:26:49Z")

</div>

@oskarkaminski.dev you’re right, @kunagpal where is the solution ?

I have the same issue. I need to passe an json object as variable.  
My pre-request Scripts:

```auto
var billingAddress = {
    "address": "('è`@&) 217 rue du loup billing",
    "address2": "complement billing ('è`@&)",
    "city": "XXX ('è`@&)",
    "country": "FR",
    "firstName": "XXXX billing ('è`@&)",
    "lastName": "XXXX billing ('è`@&)",
    "zipCode": "76000",
    "company": "XXXX Inc billing ('è`@&)"
};

//pm.environment.set('billingAddress', JSON.stringify(billingAddress));
pm.variables.set('billingAddress', JSON.stringify(billingAddress));

```

My body request:

```auto
{
    "orderId": {{$timestamp}},
    "notified_url":"https://webhook.site/XXX-4ff8-a04d-XXX",
    "billingAddress": "{{billingAddress}}",
   ...
}

```

I tried several syntaxes for get **billingAddress** but look as follow in my request:

{  
“orderId”: 1642410931,  
“notified\_url”:“[https://webhook.site/XXX-4ff8-a04d-XXX](https://webhook.site/XXX-4ff8-a04d-XXX)”,  
“billingAddress”: “{{ **billingAddress** }}”,  
…  
}
