# Error Paring JSON response -- JSONError: Unexpected token u

**URL:** <https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988>\
**Category:** Help Hub\
**Tags:** tests, json\
**Created:** [February 3, 2021, 11:29pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988 "2021-02-03T23:29:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![markeastwood](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@markeastwood](https://community.postman.com/u/markeastwood)\
**Post date:** [February 3, 2021, 11:29pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/1 "2021-02-03T23:29:08Z")

</div>

I’m developing a pre-request script. This script does a POST to get a JWT that I’ll use for my main request. The POST returns with a http 200 so all good… if I comment out the attempted parse, it all completes with no issue. I have a result that passes JSONlint … so I didn’t expect any issues.

 ![image_2](https://us1.discourse-cdn.com/getpostman/original/2X/6/628d692923ba1ac2c111c90a6ec2a6b9f8383f0d.jpeg) ![image_3](https://us1.discourse-cdn.com/getpostman/original/3X/4/3/4344f16c28d2d1854de64371951d76a4bbd60d21.jpeg) ![inage_1](https://us1.discourse-cdn.com/getpostman/original/2X/6/65695b569ed0c23b9b9a268e3fa3b5ed874f4b62.jpeg)

Its a simple response and I simply want to get the “val” attribute but the JSONParse fails.  
The Postman console says “JSONError: Unexpected token u in JSON at position 0” and as you can see there’s no “u” attribute in the response. Yes, I see that inside the value for “val” the letter ‘u’ turns up… that can’t be the issue.

How can I sort out what’s happening so I can make this work?

{  
“tt”: “JWT”,  
“val”: “eyJraWQiOiJJYW1Kd2tLZXkiLCJhbGciOiJFUzI1NiJ9.eyJqdGkiOiJKMFZjazlsaDc2QlVQdnBrenJVU3hnIiwiaWF0IjoxNjEyMzk0NjUwLCJpc3MiOiJJQU0iLCJhdWQiOiIxMjduamNsZW14OSIsInN1YiI6IjEyN25qY2xlbXg5IiwiZXhwIjoxNjEyMzk1NTUwLCJ0a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2VJbnN0YW5jZTovY29tLmZpY28uZG1wLm1lc3NhZ2luZy9raW5lc2lzL3Jlc3Qvc2VydmljZS9zb2x1dGlvbmluc3RhbmNlcy8xMjdubWtpMTBtbS9hcGlcIixcInNlcnZpY2VJbnN0YW5jZTovY29tLmZpY28uZG1wLnMzL3Jlc3Qvc2VydmljZS9zb2x1dGlvbmluc3RhbmNlcy8xMjdubjRsOXZndC9hcGlcIixcInNlcnZpY2VJbnN0YW5jZTovY29tLmZpY28uZG1wLnMzL3Jlc3Qvc2VydmljZS9zb2x1dGlvbmluc3RhbmNlcy8xMjdubXRzYXc1ay9hcGlcIixcInNlcnZpY2VJbnN0YW5jZTovY29tLmZpY28uZG1wLnMzL3Jlc3Qvc2VydmljZS9zb2x1dGlvbmluc3RhbmNlcy8xMjdub2c1M2ZybS9hcGlcIl0sXCJyZXN0cmljdGlvbnNcIjp7XCJ0ZW5hbnRpZFwiOlwiRklDTy1GSUVMRC1URU5BTlRcIixcImVuYWJsZWxjbVwiOlwidHJ1ZVwiLFwibWF4Y29tcG9uZW50c1wiOlwiNVwiLFwiZW5hYmxlZmFzdFwiOlwidHJ1ZVwifSxcInJlYWxtXCI6XCIvRmljb0FuYWx5dGljQ2xvdWRcIixcInRva2VuX3R5cGVcIjpcIkJlYXJlclwiLFwiZXhwaXJlc19pblwiOjM1OTksXCJvXCI6XCJGSUNPLUZJRUxELVRFTkFOVFwifSIsImtpZCI6IkZpY29BbmFseXRpY0Nsb3VkIn0.EuD6sBbUfFYSuJ7EgZdz7s5j4bksLl9nlfu1-i0mZSnREnXf\_GWTCiu0FA34AZnSKzTjW\_Lu82lRnx6taoQ6Vw”,  
“v”: “1.0”,  
“exp”: 1612395550  
}

---

<div class="post-metadata">

**Author:** ![markeastwood](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@markeastwood](https://community.postman.com/u/markeastwood)\
**Post date:** [February 3, 2021, 11:54pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/2 "2021-02-03T23:54:27Z")

</div>

I think I see what’s happening here… but I don’t know what to do about it. If I manually create a request that’s a POST as above (same content as in my pre-request script) I get a response body… I can see it in the UI (same as above) … but if I make a POST in the pre-request script I don’t have a body… I have status and status-code and the response headers, stream… but there’s no body like I would have if I made a GET.

I can’t use GET, I have to use POST (its not my interface) …

Is there anything I can do?

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [February 4, 2021, 4:19am UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/3 "2021-02-04T04:19:33Z")

</div>

Can you try to do log of response before parsing to JSON.  
console.log(response.body);  
And check how data is coming in response.  
If there is no data for it try to do console.log(response);  
Then we can try to extract the data

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [February 4, 2021, 6:56am UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/4 "2021-02-04T06:56:40Z")

</div>

May be this [blog](https://dannydainton.com/2018/09/10/postman-the-bearer-of-good-news/) can help you 🙂

---

<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:** [February 4, 2021, 7:50am UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/5 "2021-02-04T07:50:39Z")

</div>

You don’t need to parse that response like that, it’s not the same as the main response.

You would just need to use this in the `sendRequest()` function:

```auto
pm.environment.set('jwt-token', response.json().val)

```

---

<div class="post-metadata">

**Author:** ![markeastwood](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@markeastwood](https://community.postman.com/u/markeastwood)\
**Post date:** [February 4, 2021, 1:52pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/6 "2021-02-04T13:52:00Z")

</div>

Thanks, I tried that even before posting - console.info( response.body );  
I get “undefined” in the logs… which is why I’m seeing the “u” parse error that complains about an unexpected token “u” …

I DO have a response object.

{id: “344e2763-ca69-46e4-a10c-f8527b5bc2d9”, status: “OK”, code: 200…}

1. id: “344e2763-ca69-46e4-a10c-f8527b5bc2d9”
2. status: “OK”
3. code: 200
4. ▶header: [5]
5. ▶stream: {…}
6. cookie: [0]
7. responseTime: 3960
8. responseSize: 2229

---

<div class="post-metadata">

**Author:** ![markeastwood](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@markeastwood](https://community.postman.com/u/markeastwood)\
**Post date:** [February 4, 2021, 1:53pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/7 "2021-02-04T13:53:14Z")

</div>

> [@danny-dainton](#):
>
> `response.json().val`

BINGO, I think I’m getting some where …

---

<div class="post-metadata">

**Author:** ![markeastwood](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@markeastwood](https://community.postman.com/u/markeastwood)\
**Post date:** [February 4, 2021, 2:06pm UTC](https://community.postman.com/t/error-paring-json-response-jsonerror-unexpected-token-u/19988/8 "2021-02-04T14:06:29Z")

</div>

> [@danny-dainton](#):
>
> You don’t need to parse that response like that, it’s not the same as the main response.
> 
> You would just need to use this in the `sendRequest()` function:
> 
> `pm.environment.set('jwt-token', response.json().val)`

Thanks, I’ll review and maybe there’s another trick in there for me to learn.
