# How can I search the entire response for a specific value?

**URL:** <https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 28, 2021, 9:44am UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264 "2021-06-28T09:44:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@Leon](https://community.postman.com/u/Leon)\
**Post date:** [June 28, 2021, 9:44am UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264/1 "2021-06-28T09:44:26Z")

</div>

Hello. Sorry for the noob question.

How can I search the entire response for a specific value? In this case the value I am using as my assertion would be let’s say “222222”, this has been set as an environment variable (“provId”) in another request and I need to be able to assert that it appears in this second request.

Below is a small snippet of the response I’m working with, the acual response would be much larger and the value “222222” could appear anywhere within.

[  
{  
“eventId”: “123456”,  
“mappings”: [  
{  
“provider”: “ABC”,  
“providerId”: “111111”,  
“confidence”: 1.0  
}  
]  
},  
{  
“eventId”: “246810”,  
“mappings”: [  
{  
“provider”: “ABC”,  
“providerId”: “222222”,  
“confidence”: 1.0  
}  
]  
},  
{  
“eventId”: “135791”,  
“mappings”: [  
{  
“provider”: “ABC”,  
“providerId”: “333333”,  
“confidence”: 1.0  
}  
]  
}  
]

I have managed to write a bit of code to check the correct value from the 1st object (below) but I need it to search the whole response.

const body = pm.response.json();  
pm.test(“placeholder” + pm.variables.get(“provId”), function() {  
pm.response.to.have.jsonBody("[0][mappings].[0][providerId]", pm.variables.get(“provId”) );  
});

---

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [June 28, 2021, 11:38am UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264/2 "2021-06-28T11:38:31Z")

</div>

Hi @Leon Welcome to the Community 🙂

Tried to add the response via postman echo:

```auto
{
    "args": {},
    "data": [
        {
            "eventId": "123456",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "111111",
                    "confidence": 1
                }
            ]
        },
        {
            "eventId": "246810",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "222222",
                    "confidence": 1
                }
            ]
        },
        {
            "eventId": "135791",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "333333",
                    "confidence": 1
                }
            ]
        }
    ],
    "files": {},
    "form": {},
    "headers": {
        "x-forwarded-proto": "https",
        "x-forwarded-port": "443",
        "host": "postman-echo.com",
        "x-amzn-trace-id": "Root=1-60d9ae0f-490add847b36b287777bd907",
        "content-length": "390",
        "content-type": "application/json",
        "user-agent": "PostmanRuntime/7.28.1",
        "accept": "*/*",
        "cache-control": "no-cache",
        "postman-token": "35370ccc-0ebb-4e84-938b-9c65b4ff563a",
        "accept-encoding": "gzip, deflate, br",
        "cookie": "sails.sid=s%3AGagXy-GC8a3ZnoOXWxQjcboSzysfmNLH.VYgXzch5Kjdnxk0COTbsRl82CXQ%2BbRhWqML83v%2F7PCw"
    },
    "json": [
        {
            "eventId": "123456",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "111111",
                    "confidence": 1
                }
            ]
        },
        {
            "eventId": "246810",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "222222",
                    "confidence": 1
                }
            ]
        },
        {
            "eventId": "135791",
            "mappings": [
                {
                    "provider": "ABC",
                    "providerId": "333333",
                    "confidence": 1
                }
            ]
        }
    ],
    "url": "https://postman-echo.com/post"
}

```

Here is the assertion to find the property id:

```auto
var resp = pm.response.json();

console.log(resp);

 for (var i = 0;i<resp.data.length;i++) 

{

     value = pm.environment.get("value_check"); //env variable that has the property id

     //console.log(value);

     if (resp.data[i].mappings[0].providerId == value)

     {

         console.log("Property ID found for : " +resp.data[i].eventId);

     }

     else 

     {

         console.log("Property ID not found for : " +resp.data[i].eventId);

     }

}

```

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [June 28, 2021, 6:09pm UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264/3 "2021-06-28T18:09:44Z")

</div>

```
let a =
    [
        {
            "eventId": "123456",
            "mappings": [{
                "provider": "ABC",
                "providerId": "111111",
                "confidence": 1.0
            }
            ]
        },
        {
            "eventId": "246810",
            "mappings": [{
                "provider": "ABC",
                "providerId": "222222",
                "confidence": 1.0
            }
            ]
        },
        {
            "eventId": "135791",
            "mappings": [{
                "provider": "ABC",
                "providerId": "333333",
                "confidence": 1.0
            }
            ]
        }
    ]

console.log(a.find(elem => elem.mappings[0].providerId === "333333"))

```

use array.find

---

<div class="post-metadata">

**Author:** ![Leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@Leon](https://community.postman.com/u/Leon)\
**Post date:** [June 30, 2021, 8:39am UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264/4 "2021-06-30T08:39:56Z")

</div>

Thank you very much. I ended up adapting it slightly to the below (mainly as the response I am working with is inside an unnamed array)

var resp = pm.response.json();  
console.log(resp);  
for (var i = 0;i\<resp.length;i++)  
{  
if (resp[i].mappings[0].providerId == pm.variables.get(“provId”))  
{  
console.log("PASSED TEST : " +resp[i].eventId);  
}  
else  
{  
console.log("FAILED TEST : " +resp[i].eventId);  
}  
}

---

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [June 30, 2021, 4:14pm UTC](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264/5 "2021-06-30T16:14:56Z")

</div>

Hi @Leon.

Glad it helped 🙂
