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

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”: [_
_ ],_
_ ],_
_ },_
]

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!