# Unable to define JSON.parse(responseBody) in Collection tests tab

**URL:** <https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405>\
**Category:** Help Hub\
**Created:** [December 4, 2019, 10:01am UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405 "2019-12-04T10:01:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven\_kp](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@steven\_kp](https://community.postman.com/u/steven_kp)\
**Post date:** [December 4, 2019, 10:01am UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405/1 "2019-12-04T10:01:18Z")

</div>

Hi everyone,

I’m currently trying to optimize my tests in Postman and wanted to use the Tests tab of my Collections for test I run almost all the time for each request.

I was just wondering if you guys knew why I can’t set a jsonData directly in this tab. Instead I have to call this variable in the Tests tab for all my requests.

Console is showing :

> ReferenceError: jsonData is not defined

What I want to do and does not work :

[postmancollectiontestissue|637x326](https://community.postman.com/uploads/short-url/nM8b2KKSScNUwjK5WTjPbqEtXXG.png)

Thank you !

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [December 4, 2019, 2:01pm UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405/2 "2019-12-04T14:01:44Z")

</div>

I don’t see where you are consuming jsonData in your screenshot. I see it is being declared, but not actually used.  
Are you able to post your code that is actually failing?

I was able to get it collection tests working using two different methods:

```auto
let jsonData = JSON.parse(responseBody);

```

and

```auto
let jsonData = pm.response.json();

```

---

<div class="post-metadata">

**Author:** ![steven\_kp](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@steven\_kp](https://community.postman.com/u/steven_kp)\
**Post date:** [December 4, 2019, 2:19pm UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405/3 "2019-12-04T14:19:08Z")

</div>

The screenshot I attached was more to show how I want my global template in my collection to be.  
jsonData depends on what the response of my request is so it’s normal (to me) not to use it at a collection level.  
Here’s an example for a request :

 ![postmancollectiontestissue2](https://us1.discourse-cdn.com/getpostman/original/3X/6/1/612129d48c60e638367968367ed022c68d936895.png)  
I tried to update my collection with one of your method but it doesn’t seem to work better, unfortunately

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [December 11, 2019, 4:48pm UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405/4 "2019-12-11T16:48:47Z")

</div>

I think I understand what you’re trying to do now.

In your request tests, you are trying to reference a variable you declared in your Collection tests.

You’re trying to save a line of code in each of your request tests. Got it 👍

Unfortunately I don’t have an answer on that, but maybe somebody else will.

---

<div class="post-metadata">

**Author:** ![morleym\_cubic](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@morleym\_cubic](https://community.postman.com/u/morleym_cubic)\
**Post date:** [December 11, 2019, 6:10pm UTC](https://community.postman.com/t/unable-to-define-json-parse-responsebody-in-collection-tests-tab/9405/5 "2019-12-11T18:10:39Z")

</div>

The best idea I could come up with is to stuff it into a collection variable on the collection test script, and then reference that in the request-level test script.

But that **still requires you to declare a variable in the test script and set it equal to the collection variable value** , and in fact would be a longer line of code than just declaring it in the test script as `const jsonData = pm.response.json();`

So tl;dr I don’t think there’s a way to automatically declare and assign to a variable for every request test script (at least not a way that will have any practical benefit)
