Check if an array contains already defined objects

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

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;
}

});