# JSONError in Collection Runner on non-JSON response

**URL:** <https://community.postman.com/t/jsonerror-in-collection-runner-on-non-json-response/12589>\
**Category:** Help Hub\
**Created:** [May 12, 2020, 2:48pm UTC](https://community.postman.com/t/jsonerror-in-collection-runner-on-non-json-response/12589 "2020-05-12T14:48:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.brooks](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@michael.brooks](https://community.postman.com/u/michael.brooks)\
**Post date:** [May 12, 2020, 2:48pm UTC](https://community.postman.com/t/jsonerror-in-collection-runner-on-non-json-response/12589/1 "2020-05-12T14:48:31Z")

</div>

I have a query that elicits a plain text response. In Postman I have configured the query’s headers to include Content-Type=text/plain, but when I run the query in Collection Runner I always get:  
JSONError: Unexpected token ‘M’ at 1:1  
MTR=20&PGTR=20P&authCode=240966&amount=1000&result=0&digest=ec0406d173c7301a632^

Collection Runner then stops instead of proceeding to run the next request in my collection.  
When I force Collection Runner to run the next request, it fails to pick up a variable that was set by the previous query’s test script, even though I have “Keep variable values” checked. I am open to the possibility that these latter issues might be as a result of the first, although I have some doubt - the test script has clearly run because I get shown the results of its tests in Collection Runner, so the variable should have persisted.

The variable is set by this code:

var respData = JSON.parse(responseBody);  
pm.variables.set(“PGTR”, respData.PGTR);

The following request accesses the variable using the standard {{PGTR}} syntax. I know it isn’t being picked up because the console shows that the {{PGTR}} (albeit URL-encoded) has been included in the query rather than substituted.

Anyone any ideas?

---

<div class="post-metadata">

**Author:** ![SabriH](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@SabriH](https://community.postman.com/u/SabriH)\
**Post date:** [May 12, 2020, 9:09pm UTC](https://community.postman.com/t/jsonerror-in-collection-runner-on-non-json-response/12589/2 "2020-05-12T21:09:50Z")

</div>

Hi @michael.brooks,

Welcome to the community! 👋

I believe you mentioned the response is a non-JSON response, correct?

The error you are seeing is most likely due to you attempting to do `JSON.parse()` on a String ( assuming `responseBody` is “MTR=20&PGTR=20P&authCode=240966&amount=1000&result=0&digest=ec0406d173c7301a632^” right? )

More information on how `JSON.parse()` works can be found here:

> **[JSON.parse() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)**
>
> The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.

If your `responseBody` is just the string “MTR=20&PGTR=20P&authCode=240966&amount=1000&result=0&digest=ec0406d173c7301a632^” , you could do something like `var pgtr = responseBody.substring(12,14); // should return 20 here` and then set the variable accordingly.

More information on substring can be found here: [String.prototype.substring() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring).

Hopefully, this helps.

---

<div class="post-metadata">

**Author:** ![michael.brooks](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@michael.brooks](https://community.postman.com/u/michael.brooks)\
**Post date:** [May 13, 2020, 6:58am UTC](https://community.postman.com/t/jsonerror-in-collection-runner-on-non-json-response/12589/3 "2020-05-13T06:58:59Z")

</div>

Thanks Sabri - I’d like to say can’t believe I did something that stupid but I’d be lying if I did. It’s still sickening though. 🤮  
I copied an example from the documentation into my test script without even thinking about it. It was of course written with the expectation that the response was formatted as JSON. D’oh!
