# Test Array for Object

**URL:** <https://community.postman.com/t/test-array-for-object/12632>\
**Category:** Help Hub\
**Tags:** tests, setnextrequest, collection-runner\
**Created:** [May 13, 2020, 10:21pm UTC](https://community.postman.com/t/test-array-for-object/12632 "2020-05-13T22:21:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![austin4778](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@austin4778](https://community.postman.com/u/austin4778)\
**Post date:** [May 13, 2020, 10:21pm UTC](https://community.postman.com/t/test-array-for-object/12632/1 "2020-05-13T22:21:40Z")

</div>

Trying to implement a test to validate an object/property exists in the array. If it doesn’t exist I would like to have it run another request. Is this possible?

Here is a small snippet of the response I am working with. Some responses will return:

```
<Target>
            <ComputerID>10278461</ComputerID>

```

Where as others may return:

```
<Target>
            <CustomRelevance>Group contains 123</CustomRelevance>

```

Essentially if ComputerID doesn’t exist then I would like for a different request to be issued to accommodate. I assume setnextrequest would be the clause to use if ComputerID doesn’t exist?

Any assistance is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![austin4778](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@austin4778](https://community.postman.com/u/austin4778)\
**Post date:** [May 13, 2020, 10:37pm UTC](https://community.postman.com/t/test-array-for-object/12632/2 "2020-05-13T22:37:17Z")

</div>

I am looking for something along the lines of:

```
pm.test('ComputerID Object Exists', function() {
  pm.expect(responseJson.BES.MultipleActionGroup.Target).to.have.property('ComputerID') })
{else 
    postman.setNextRequest()}
```

---

<div class="post-metadata">

**Author:** ![hannah.neil](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/hannah.neil/32/4477_2.png) [@hannah.neil](https://community.postman.com/u/hannah.neil)\
**Post date:** [May 15, 2020, 9:10pm UTC](https://community.postman.com/t/test-array-for-object/12632/3 "2020-05-15T21:10:39Z")

</div>

Hi @austin4778, does this post help answer your question?

> [@How to check that each objects from response contains particular key?](https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788/2):
>
> To validate the Json format and contents I recommend you to use the AJV library, it has powerful features to validate Json response contents. The following code might solve your problem. pm.test(“Response contains property”,function() { var Ajv = require(‘ajv’); var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} //Json schema to be validated var schema = { “type”: “array”, “items”: { “type” : “object”, “required”: [“Id”] } }; var jsonData = pm.response.json(); var jsonV…

---

<div class="post-metadata">

**Author:** ![Aditya\_Keshavamurthy](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Aditya\_Keshavamurthy](https://community.postman.com/u/Aditya_Keshavamurthy)\
**Post date:** [May 16, 2020, 8:33am UTC](https://community.postman.com/t/test-array-for-object/12632/4 "2020-05-16T08:33:37Z")

</div>

Hi!!! I have a array response as below, which will change dynamically with addition of data.  
I have a value set in Environment variable from a POST call, and how do I search that value in the GET request. So I need to parse the array objects and stop at the value which is matching the environment variable value  
[  
{  
“id”: “0cb0e4cf-0bcd-4234-b84d-839bbc1c823e”,  
“name”: “4gclinical Data Source”,  
“nameKey”: “SecurityDataSource”  
},  
{  
“id”: “e0a7ac43-1713-4193-b846-3ff379ef8b95”,  
“name”: “a corporis repudiandae”,  
“nameKey”: “facilis”  
},  
{  
“id”: “b1004fd5-446d-497c-96ff-8c06e9d1bd43”,  
“name”: “ab assumenda accusamus”,  
“nameKey”: “{{randomLoremWord}}”  
},  
{  
“id”: “4e92809e-acb9-4ed0-b64b-a399554a7c7d”,  
“name”: “adipisci sunt molestiae”,  
“nameKey”: “et”  
},  
{  
“id”: “d80d72a2-8f5a-4e96-b05a-f737ffdb2bc8”,  
“name”: “adipisci voluptas et”,  
“nameKey”: “quas”  
},  
{  
“id”: “92320fcd-22b9-48c7-8d71-996d933190d4”,  
“name”: “alias dignissimos minus”,  
“nameKey”: “sint”  
},  
{  
“id”: “bedc2f46-ef6e-4c13-bd81-8ff007afa5a4”,  
“name”: “alias voluptas sed”,  
“nameKey”: “consectetur”  
},  
{  
“id”: “1fcd7cf2-eb66-4272-ba26-408233bfc845”,  
“name”: “AM enterprise data source”,  
“nameKey”: “amenterDataSource”  
},  
{  
“id”: “91b1f5ec-b1c2-4748-a2ef-0e0206e8e7fc”,  
“name”: “Anti-Slavery”,  
“nameKey”: “DataSourceCategory.Anti-Slavery”  
},  
{  
“id”: “a103d33a-9bd3-4780-8c90-9e3ef9ac8aff”,  
“name”: “Assessment1”,  
“nameKey”: “AssessmentNameKey”  
},  
{  
“id”: “9552e93c-632b-4465-8dbe-b8a7081177dd”,  
“name”: “aut est distinctio”,  
“nameKey”: “voluptas”  
},  
{  
“id”: “5c4621dc-5245-4496-a174-03f1692b13ab”,  
“name”: “c-afbnyci”,  
“nameKey”: “c-afbnyci”  
},  
{  
“id”: “ec645c4b-5fb5-4c57-929f-7dfc3ba0c6fb”,  
“name”: “c-cmrwcmm”,  
“nameKey”: “c-cmrwcmm”  
},  
{  
“id”: “2191cd32-6c41-4366-b076-47d761475a4c”,  
“name”: “c-nkkdpkw”,  
“nameKey”: “c-nkkdpkw”  
},  
{  
“id”: “3c332983-6101-42b5-a1f0-ae9260289b84”,  
“name”: “c-nznmffl”,  
“nameKey”: “c-nznmffl”  
},  
{  
“id”: “bc4bff4e-8fac-4231-944c-6798c338cb36”,  
“name”: “C-rfwtane”,  
“nameKey”: “C-rfwtane”  
},  
{…}  
]

The array would keep on increasing as and when I add value using post call. Please help me out with how to map a value which is set in the environment variable from POST call to search in GET call.
