# 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:** 1\
**Showing post:** 2

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

---

_[View the full topic](https://community.postman.com/t/how-to-check-that-each-objects-from-response-contains-particular-key/3788)._
