# How to check that each objects from response contains particular key?

**URL:** <https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [January 10, 2019, 5:43pm UTC](https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788 "2019-01-10T17:43:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexTkachenko](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AlexTkachenko](https://community.postman.com/u/AlexTkachenko)\
**Post date:** [January 10, 2019, 5:43pm UTC](https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788/1 "2019-01-10T17:43:25Z")

</div>

Guys please help with testing next - i’m receiving response where are more then 500 objects (1 sample is bellow), and i need to be sure that each object contains the KEY “id”, as some of them don’t have it, and that’s a current issue.  
**I was trying this:**  
pm.test(“Response contains property”, function () {  
pm.expect(pm.response.json()).to.have.property(‘property\_key’);  
});

_[_  
_{_  
\_ “id”: “4FXtMUs”,\_  
\_ “createdAt”: “2018-06-18T22”,\_  
\_ “updatedAt”: “2018-11-11T13”,\_  
\_ \_  
\_ {\_  
\_ “size”: 95880,\_  
\_ “bgColor”: “8ca290”,\_  
\_ “avgColor”: “7c938f”\_  
\_ },\_  
\_ “sharingLink”: {\_  
\_ },\_  
\_ “attributedDescription”: [\_  
\_ ],\_  
\_ ],\_  
\_ },\_  
_]_

---

<div class="post-metadata">

**Author:** ![spmartello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/spmartello/32/3528_2.png) [@spmartello](https://community.postman.com/u/spmartello)\
**Post date:** [January 3, 2020, 3:11pm UTC](https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788/2 "2020-01-03T15:11:31Z")

</div>

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 jsonValid = ajv.validate(schema, jsonData);  
if(!jsonValid){  
console.log("JSON Schema Validation Error: " + JSON.stringify(ajv.errors));  
}  
pm.expect(jsonValid).to.be.true;  
});

Best Regards!
