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

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



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

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))

yeah i am doing it. thanks