# How to check whether the given string is available in request body

**URL:** <https://community.postman.com/t/how-to-check-whether-the-given-string-is-available-in-request-body/14206>\
**Category:** Help Hub\
**Created:** [July 16, 2020, 10:31am UTC](https://community.postman.com/t/how-to-check-whether-the-given-string-is-available-in-request-body/14206 "2020-07-16T10:31:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdxcz](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cdxcz](https://community.postman.com/u/cdxcz)\
**Post date:** [July 16, 2020, 10:31am UTC](https://community.postman.com/t/how-to-check-whether-the-given-string-is-available-in-request-body/14206/1 "2020-07-16T10:31:04Z")

</div>

How can I check whether the given string is available in a request body?

Example:

```
{"hello":"hello","key":"kvalue"}

```

In the Pre-request Script:

```
if(pm.request.body.has(“hello”) && pm.request.body.has(“key”)) {
//do something
}

```

Edited :

i have tried matching check with  
`body.indexOf("key") >= 0` but these are not working in postman Pre-request-script

---

<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:** [July 16, 2020, 12:17pm UTC](https://community.postman.com/t/how-to-check-whether-the-given-string-is-available-in-request-body/14206/2 "2020-07-16T12:17:44Z")

</div>

You need to first understand what `pm.request.body` actually returns.

Log this value out to the Postman Console before doing any logic on it in the `if` statement.

It’s JSON, so the body would also have the type `raw` but you would still need to parse this to access the keys within it.

This might be something that can be used to access the request body data - `JSON.parse(pm.request.body.raw))`

---

<div class="post-metadata">

**Author:** ![cdxcz](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@cdxcz](https://community.postman.com/u/cdxcz)\
**Post date:** [July 16, 2020, 12:51pm UTC](https://community.postman.com/t/how-to-check-whether-the-given-string-is-available-in-request-body/14206/3 "2020-07-16T12:51:54Z")

</div>

yeah i am doing it. thanks
