# To store the entire response value in and environment variable

**URL:** <https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [November 19, 2024, 6:19am UTC](https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396 "2024-11-19T06:19:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![altimetry-explorer-3](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@altimetry-explorer-3](https://community.postman.com/u/altimetry-explorer-3)\
**Post date:** [November 19, 2024, 6:19am UTC](https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396/1 "2024-11-19T06:19:14Z")

</div>

Hello,  
I want to save it as an environment variable so that there are no missing values from the values in the body of the response.

When specified as an environment variable, a portion of the body of the response is missing and saved as shown below.

===========================================

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/a/2a9509049b83309f349394455f9b694d276198fb.png)

===========================================

> scripts  
> var data = pm.response.json();  
> pm.environment.set(“Path”, data[“Path”]);  
> ===========================================  
> environment variable  
> Path | 2024\11\19\sample.jpg  
> ===========================================

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [November 19, 2024, 3:18pm UTC](https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396/2 "2024-11-19T15:18:06Z")

</div>

Hi @altimetry-explorer-3.

Welcome to the Postman Community :postman_logo:.

What does the full data you want to store look like? I will recommend storing JSON data as a string in environments oranywhere else in Postman.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 19, 2024, 3:57pm UTC](https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396/3 "2024-11-19T15:57:38Z")

</div>

\ is an escape character in JavaScript.

If you really need to store the double back slashes, then the following should work.

```auto
let path = "2024\\11\\19\\sample.jpg";

pm.collectionVariables.set("path", JSON.stringify(path).slice(1, -1));

console.log(pm.collectionVariables.get("path")); // 2024\\11\\19\\sample.jpg

```

Taken from…

[Escaping Strings in JavaScript - Stack Overflow](https://stackoverflow.com/questions/770523/escaping-strings-in-javascript)

However, it is worth noting that you are not storing the entire response, just one value.

To store the entire response as a string.

```auto
pm.collectionVariables.set("fullResponse",(JSON.stringify(pm.response.json())));
console.log(pm.collectionVariables.get("fullResponse")) // "{"Path":"2024\\11\\19\\sample.jpg"}"

```

The problem I can see with this is when you parse it, you are going to have the same problem and the leading escape character will be removed.

```auto
console.log(JSON.parse(pm.collectionVariables.get("fullResponse"))); // {Path: "2024\11\19\sample.jpg"}

```

Ideally if you have control of the API in question, you should speak to the developer and get them to encode the backslashes in the response using %5C

```auto
{
    "Path": "2024%5C%5C11%5C%5C19%5C%5Csample.jpg"
}

```

You can then use the JavaScript decodeURI function.

```auto
console.log(decodeURI(pm.response.json().Path)); // "024\\11\\19\\sample.jpg"

```

---

<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:** [December 19, 2024, 3:58pm UTC](https://community.postman.com/t/to-store-the-entire-response-value-in-and-environment-variable/71396/4 "2024-12-19T15:58:03Z")

</div>

Closed on December 19, 2024, 3:58pm UTC

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