# Tests pm.request.body output all key value

**URL:** <https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 21, 2019, 7:33am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513 "2019-05-21T07:33:16Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![aisen0921](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@aisen0921](https://community.postman.com/u/aisen0921)\
**Post date:** [May 21, 2019, 7:33am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/1 "2019-05-21T07:33:17Z")

</div>

I’m trying print the request body at “Test Results” :

![2019-05-21%2017%2006%2009](https://us1.discourse-cdn.com/getpostman/original/3X/7/8/78b1339f4ffdd4230488fb09a85ddd1b67a6fbd1.png)

My Params and Test Results:

![2019-05-21%2017%2013%2029](https://us1.discourse-cdn.com/getpostman/original/3X/3/b/3bc427025f75dec6f9c6ae4610cfe39344dab6bd.png)

But `name=bbb&password=456` is not my truly request body.  
How to only print `name=aaa&password=123`?

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:** [May 21, 2019, 8:33am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/2 "2019-05-21T08:33:48Z")

</div>

Hey @aisen0921

Welcome to the community 👋

I’m unsure what you’re asking, would you be able to expand on the information in the question, please?

What are you trying to Test? What is the expected outcome?

If you wanted to check the params for the request, you would probably need to access those via `pm.request.url.query`.

---

<div class="post-metadata">

**Author:** ![aisen0921](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@aisen0921](https://community.postman.com/u/aisen0921)\
**Post date:** [May 21, 2019, 9:34am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/3 "2019-05-21T09:34:04Z")

</div>

I update my question for more information.

My url like [http://url/login.json](http://url/login.json) ,and every url is endwith “.json”  
I use `pm.request.url.query` print empty.

---

<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:** [May 21, 2019, 10:11am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/4 "2019-05-21T10:11:45Z")

</div>

My bad - I think I actually read your question incorrectly. ☹

I’m still not really sure what you’re trying to do - Do you need a check in place to test for something? Currently, that’s not _testing_ anything.

`pm.request.body.urlencoded` would be what you need to see those values but this is just going to show you the same thing.

 ![30](https://us1.discourse-cdn.com/getpostman/original/2X/e/e1eec0027221745124fc81bb1806ebd5b4082bd5.png)

This is **not** what is actually sent in the request though.

If you use the Postman Console to log that output

`console.log(pm.request.body.urlencoded)`

You will see that the _disabled_ key/value pairs have the `disabled` key within the object. Postman uses this during the request to know not to send them through.

You can see the `response body` in the image that the _hidden_ key/value pairs were not sent as part of the actual request.

 ![55](https://us1.discourse-cdn.com/getpostman/original/2X/f/fcb5b37f3b71d31e33e734c246de77a02d19cc1d.jpeg)

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [May 21, 2019, 11:15am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/5 "2019-05-21T11:15:30Z")

</div>

If you see here, I’m passing “test1” and “test2”, I’ve unchecked “test3”:

 ![01](https://us1.discourse-cdn.com/getpostman/original/3X/6/5/65b23811804a1f2162da708065c5315052c520b3.png)

As Danny said, if a parameter is unchecked it’ll have this “disabled: true” key/value.  
If I console log “pm.request.body.urlencoded”, it’ll return an array of objects.

![18](https://us1.discourse-cdn.com/getpostman/original/3X/5/7/57931a00d73ce1a756168f05aa3439fb1bf982ff.png)

So I’m doing a filter on all the parameters to only show me ones that DON’T have “disabled: true”

 ![29](https://us1.discourse-cdn.com/getpostman/original/3X/5/6/5601634355350ba8816cfb116db38598a9de2354.png)

I’m console logging this:  
 ![39](https://us1.discourse-cdn.com/getpostman/original/3X/1/9/1916e48f8df40b8b3ec5bfe02a7c06e64484f6a5.png)

And here’s the valid params used as test name (Not sure what your use case for needing this but _shrugs_:  
 ![24](https://us1.discourse-cdn.com/getpostman/original/3X/5/b/5b0cc4606e3f57baae12d6e2530f4d374754be0d.png)

---

<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:** [May 21, 2019, 11:51am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/6 "2019-05-21T11:51:50Z")

</div>

This would also add those _non hidden_ values to the `Test` name but obviously as an `object` 🙂

`pm.test(JSON.stringify(pm.request.body.urlencoded.toObject(true)))`

 ![23](https://us1.discourse-cdn.com/getpostman/original/3X/8/e/8ec634545c89e2960e7928f2fcaea1a05e5a7f9f.png)

---

<div class="post-metadata">

**Author:** ![aisen0921](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@aisen0921](https://community.postman.com/u/aisen0921)\
**Post date:** [May 22, 2019, 2:10am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/7 "2019-05-22T02:10:42Z")

</div>

@danny-dainton  
That’s OK.🙂

I use “pm.test” because I want see request body、content-type、response content in Run Results, or there has another way ?  
(“Export Results” has too many detail for me.)

My requirement like this picture, it’s looks brief, can see all the necessary conditions and responses.

 ![2019-05-22%2009%2031%2049](https://us1.discourse-cdn.com/getpostman/original/3X/8/e/8e54719f5a64acaf987b45ee389cc3342122c359.png)

Thank you for providing “console.log” this method,I will use it.

@postman-paul540  
.filter is what I need, and the example is clearly, 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:** [May 22, 2019, 5:19am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/8 "2019-05-22T05:19:06Z")

</div>

You’re able to view the details of each of the requests, from the Collection Runner, by selecting the requests name:

 ![Request_Data](https://us1.discourse-cdn.com/getpostman/original/2X/d/db3851dc18851916f7207c43d86de66e9cebf7aa.gif)

This seems like the information that you want to see.

More information about this can be found here:

[https://learning.getpostman.com/docs/postman/collection\_runs/debugging\_a\_collection\_run](https://learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run)

---

<div class="post-metadata">

**Author:** ![swasthik08](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@swasthik08](https://community.postman.com/u/swasthik08)\
**Post date:** [September 25, 2020, 8:02am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/9 "2020-09-25T08:02:09Z")

</div>

JSONError: Unexpected token ‘a’ at 1:1

im facing this error ^ for below script, can some one help please

var jsonReq = JSON.parse(pm.request.body);  
var jsonRes = pm.response.json();  
console.log("Request body is as below: ");  
console.log(jsonReq);  
console.log("Response body is as below: ");  
console.log(jsonRes);

---

<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:** [September 25, 2020, 9:04am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/10 "2020-09-25T09:04:10Z")

</div>

What’s the response from that request?

Feeling like it’s trying to parse something that isn’t JSON.

---

<div class="post-metadata">

**Author:** ![swasthik08](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@swasthik08](https://community.postman.com/u/swasthik08)\
**Post date:** [September 25, 2020, 10:20am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/11 "2020-09-25T10:20:53Z")

</div>

var jsonReq = JSON.parse(pm.request.body);

this is failing^  
Request body is in urlencoded  
i tried doing

var jsonReq = JSON.parse(pm.request.body.urlencoded);  
var jsonRes = pm.response.json();  
console.log("Request body is as below: ")  
console.log(jsonReq)  
console.log("Response body is as below: ")  
console.log(jsonRes)

im getting JSONError: Unexpected token ‘a’ at 1:1

---

<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:** [September 25, 2020, 11:33am UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/12 "2020-09-25T11:33:32Z")

</div>

I’m not sure why you’re doing a `JSON.parse()` on `pm.request.body.urlencoded`

```auto
var jsonReq = pm.request.body.urlencoded;
var jsonRes = pm.response.json();
console.log("Request body is as below: ")
console.log(jsonReq)
console.log("Response body is as below: ")
console.log(jsonRes)

```

---

<div class="post-metadata">

**Author:** ![swasthik08](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@swasthik08](https://community.postman.com/u/swasthik08)\
**Post date:** [September 25, 2020, 1:40pm UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/13 "2020-09-25T13:40:53Z")

</div>

I thought JSON.parse can convert to JSON format and show in console

---

<div class="post-metadata">

**Author:** ![aziziemna37](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@aziziemna37](https://community.postman.com/u/aziziemna37)\
**Post date:** [December 14, 2020, 2:48pm UTC](https://community.postman.com/t/tests-pm-request-body-output-all-key-value/5513/14 "2020-12-14T14:48:42Z")

</div>

in my case i used formdata  
this is how i got my body.formdata.json

let body = Object.values(pm.request.body.formdata)  
let values = JSON.parse(body[1])
