# Setting variable from JSON response URL value

**URL:** <https://community.postman.com/t/setting-variable-from-json-response-url-value/30232>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [November 30, 2021, 7:13pm UTC](https://community.postman.com/t/setting-variable-from-json-response-url-value/30232 "2021-11-30T19:13:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacecraft-architec2](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@spacecraft-architec2](https://community.postman.com/u/spacecraft-architec2)\
**Post date:** [November 30, 2021, 7:13pm UTC](https://community.postman.com/t/setting-variable-from-json-response-url-value/30232/1 "2021-11-30T19:13:21Z")

</div>

I would like to set a value from the response body as an environmental variable. The  
response property is a URL. The response looks like this:

```auto
{
    "http://url/sub/sub1": "value1",
    "http://url/sub/sub2": "value2"
}

```

I have tried adding this to the Tests tab and get unexpected Token error:

```auto
var body = JSON.parse(responseBody);
pm.environment.set('passcode', body.http://url/sub/sub1);

```

---

<div class="post-metadata">

**Author:** ![jmaugeri](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jmaugeri](https://community.postman.com/u/jmaugeri)\
**Post date:** [December 1, 2021, 2:16pm UTC](https://community.postman.com/t/setting-variable-from-json-response-url-value/30232/2 "2021-12-01T14:16:32Z")

</div>

`pm.environment.set('passcode', body.http://url/sub/sub1);` will not work because your property name contains special characters (the invalid token), you need to use braket notation

`pm.environment.set('passcode', body['http://url/sub/sub1']);`
