# Test script using main body data

**URL:** <https://community.postman.com/t/test-script-using-main-body-data/44048>\
**Category:** Help Hub\
**Tags:** body, parameters, test\
**Created:** [February 16, 2023, 1:31am UTC](https://community.postman.com/t/test-script-using-main-body-data/44048 "2023-02-16T01:31:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelcarrasco](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@samuelcarrasco](https://community.postman.com/u/samuelcarrasco)\
**Post date:** [February 16, 2023, 1:31am UTC](https://community.postman.com/t/test-script-using-main-body-data/44048/1 "2023-02-16T01:31:43Z")

</div>

**_My question_:**  
I want to take the data I have in my body and utilize it in a Test script. Such as, whatever is inputted into the “id” field will be tested against the received data, and I don’t manually have to input it as a parameter. Therefore using “id” in the body as a parameter against the response in a test script.

\*\*_Details :_  
My body layout:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/2/b/2bda9c9ab8fc6fc242838a02a08f96706db82a01.png)

My Test layout: (highlighted in yellow is not working)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/4/5453591d9be625fdd3572be10310ad96ffe166d9.png)

_How I found the problem_:  
from my understanding, pm.response.json() is the data receieved. Therefore I cannot use it to get the id from the body? I can manually input the id I want to test, which will work.

Side Note:  
I tried using jsonData on my Eligible test, but it wasn’t working. Then I used the pm.response.json()[0].Eligible).to.eql(true) and that worked. So I left it.

**_I’ve already tried_:**  
I have tried different responses from the help page. I commented out what I have tried but took out the var associated with them from the clutter of hours of testing.  
I tried-- “id” : “{{89784}}” in the body but that caused and Erro 500 process terminating

* * *

I welcome any documentation to help me further progress.

I will continue looking at the documentation. If I find a solution, I will take down the post. Thank You.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 16, 2023, 10:45am UTC](https://community.postman.com/t/test-script-using-main-body-data/44048/2 "2023-02-16T10:45:31Z")

</div>

The following should work.

```auto
const requestJson = JSON.parse(pm.request.body.raw);
const responseJson = pm.response.json()

let employeeID = responseJson[0].Employee_ID;

pm.test(`expect employee id to equal ${requestJson.id}`, () => {
    pm.expect(employeeID).to.eql(requestJson.id);
})

```

---

<div class="post-metadata">

**Author:** ![samuelcarrasco](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@samuelcarrasco](https://community.postman.com/u/samuelcarrasco)\
**Post date:** [February 16, 2023, 2:19pm UTC](https://community.postman.com/t/test-script-using-main-body-data/44048/3 "2023-02-16T14:19:05Z")

</div>

I appreciate your help. This was the solution. I now know how JSON.parse is used. I read that it was needed to fix the issue, but I didn’t know how it was used. Thank you again.
