# Check if an array contains already defined objects

**URL:** <https://community.postman.com/t/check-if-an-array-contains-already-defined-objects/12574>\
**Category:** Help Hub\
**Tags:** tests, json, schema\
**Created:** [May 12, 2020, 8:06am UTC](https://community.postman.com/t/check-if-an-array-contains-already-defined-objects/12574 "2020-05-12T08:06:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![plcmaechler](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/plcmaechler/32/4500_2.png) [@plcmaechler](https://community.postman.com/u/plcmaechler)\
**Post date:** [May 12, 2020, 8:06am UTC](https://community.postman.com/t/check-if-an-array-contains-already-defined-objects/12574/1 "2020-05-12T08:06:46Z")

</div>

Hello Community,

DRY, how can i check if an array exists of already defined JSON-Items?

Background:  
I have a JSON schema defined  
`var itemSchema = { type: "object", properties: { abc: { type: "string" } } }`

now my api has to calls

- getItem
- getList

the getItem call successfully checks if the returned item is of itemSchema. how should my test be to check if the array from getList contains those, and only those items?

one simple way that comes to mind is, to loop over all the items in the array and validate them against the schema.  
But im sure there has to be a way to say that my Array has items of itemSchema

---

<div class="post-metadata">

**Author:** ![plcmaechler](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/plcmaechler/32/4500_2.png) [@plcmaechler](https://community.postman.com/u/plcmaechler)\
**Post date:** [May 19, 2020, 6:42am UTC](https://community.postman.com/t/check-if-an-array-contains-already-defined-objects/12574/2 "2020-05-19T06:42:09Z")

</div>

```
pm.test("validate JSON Response schema", function () {
var jsonData = pm.response.json();
for (var i = 0; i < jsonData.length; i++) {
    console.log("jd" + i, jsonData[i]);
    pm.expect(ajv.validate(schema, jsonData[i]), JSON.stringify(ajv.errors)).to.be.true;
}

```

});
