# How to escape double quote when setting/using variables?

**URL:** <https://community.postman.com/t/how-to-escape-double-quote-when-setting-using-variables/13505>\
**Category:** Help Hub\
**Tags:** variables, setenvironmentvariab\
**Created:** [June 18, 2020, 2:49pm UTC](https://community.postman.com/t/how-to-escape-double-quote-when-setting-using-variables/13505 "2020-06-18T14:49:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagrdude](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jagrdude](https://community.postman.com/u/jagrdude)\
**Post date:** [June 18, 2020, 2:49pm UTC](https://community.postman.com/t/how-to-escape-double-quote-when-setting-using-variables/13505/1 "2020-06-18T14:49:00Z")

</div>

I’m making two API calls. The _first_ returns JSON with one of the values being HTML as a string.

```json
{ "html_content": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0..." }

```

In the **Tests** section, I am setting a collection variable with this string.

```javascript
pm.collectionVariables.set("htmlContent", pm.response.json().html_content)

```

Then, in the _second_ API call, I am trying to POST the HTML string.

```json
{ "html_content": "{{htmlContent}}" }

```

However, I’m getting a 400 because Postman is sending the string _without_ the double quotes escaped, so the JSON is malformed.

```json
{ "html_content": "<!DOCTYPE html PUBLIC "- //W3C//DTD XHTML 1.0... }

```

But if I simply _copy_ the HTML output from the first API call and _paste_ it into the second API call, it works (because the escaped double-quotes are still there).

So, my question is this: how do I instruct Postman to keep the escaping in place when I use the collection variable?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 18, 2020, 3:19pm UTC](https://community.postman.com/t/how-to-escape-double-quote-when-setting-using-variables/13505/2 "2020-06-18T15:19:49Z")

</div>

Hey @jagrdude

Welcome to the community!! ⭐

This might be what you need:

```
pm.collectionVariables.set("htmlContent", JSON.stringify(pm.response.json().html_content))

```

And then use this in the POST body like this:

```
{
    "html_content": {{htmlContent}}
}

```

---

<div class="post-metadata">

**Author:** ![jagrdude](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jagrdude](https://community.postman.com/u/jagrdude)\
**Post date:** [June 18, 2020, 3:27pm UTC](https://community.postman.com/t/how-to-escape-double-quote-when-setting-using-variables/13505/3 "2020-06-18T15:27:09Z")

</div>

@danny-dainton - you’re the man! That did the trick. 👍

I know I tried a variation of that, but I think my misstep was I left the double quotes around the variable reference: `"{{htmlContent}}"`

Removing that _along with_ the stringifying was the solution.

Thanks for the help and quick response!
