# Help with JSON extraction

**URL:** <https://community.postman.com/t/help-with-json-extraction/5155>\
**Category:** Help Hub\
**Tags:** json\
**Created:** [April 25, 2019, 4:33pm UTC](https://community.postman.com/t/help-with-json-extraction/5155 "2019-04-25T16:33:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giuseppe.lacagnina](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/giuseppe.lacagnina/32/1689_2.png) [@giuseppe.lacagnina](https://community.postman.com/u/giuseppe.lacagnina)\
**Post date:** [April 25, 2019, 4:33pm UTC](https://community.postman.com/t/help-with-json-extraction/5155/1 "2019-04-25T16:33:50Z")

</div>

Hi.

I am doing my first steps towards an “advanced” use of Postman. I am trying to extract data from a JSON response. The JSON response looks like:

```
{
    "args": {},
    "headers": {
        "x-forwarded-proto": "https",
        "host": "postman-echo.com",
        "accept": "*/*",
        "accept-encoding": "gzip, deflate",
        "cache-control": "no-cache",
        "cookie": "sails.sid=s%3AgX-JxoOgGc7tWEb8jw_6YBH5VKcxH8R8.M7J38uMcN090VYnxRHu6eF4rkq7arAemQXhfRd9TWz4",
        "postman-token": "b5ef1d87-d4fc-4ec4-b961-6a412a06a0d1",
        "user-agent": "PostmanRuntime/7.11.0",
        "x-forwarded-port": "80"
    },
    "url": "https://postman-echo.com/get"
}

```

when I try something like

```
var data = pm.response.json();
pm.environment.set("host", data.headers.host);

```

It works perfectly. If however I add

`pm.environment.set("responseToken", data.headers.postman-token);`

I have an error:

> ReferenceError | token is not defined

I imagine this has to do with the “-” character in the field name.

Can anyone help me? Thanks!!!

---

<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:** [April 25, 2019, 5:15pm UTC](https://community.postman.com/t/help-with-json-extraction/5155/2 "2019-04-25T17:15:39Z")

</div>

Hey @giuseppe.lacagnina,

Welcome to the community! 🙂

So you _should_ be able to wrap that in `brackets` to get the value from that key.

`pm.environment.set("responseToken", data.headers['postman-token'])`

As it has the `-` character in the `key` you would need to use the bracket notation rather than the dot notation.

Some more information on the different notation methods can be found here:

> **[JavaScript Quickie— Dot Notation vs. Bracket Notation](https://codeburst.io/javascript-quickie-dot-notation-vs-bracket-notation-333641c0f781)**
>
> What’s the difference? When is each useful? Learn the details in 3 minutes

---

<div class="post-metadata">

**Author:** ![giuseppe.lacagnina](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/giuseppe.lacagnina/32/1689_2.png) [@giuseppe.lacagnina](https://community.postman.com/u/giuseppe.lacagnina)\
**Post date:** [April 25, 2019, 5:17pm UTC](https://community.postman.com/t/help-with-json-extraction/5155/3 "2019-04-25T17:17:30Z")

</div>

> [@danny-dainton](#):
>
> pm.environment.set(“responseToken”, data.headers[‘postman-token’])

Thanks a lot, it worked!!! All the examples around do not contemplate such cases.

---

<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:** [April 25, 2019, 5:19pm UTC](https://community.postman.com/t/help-with-json-extraction/5155/4 "2019-04-25T17:19:32Z")

</div>

You’re welcome!! Glad it worked for you!! 🏆
