Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.
Hi this is an example!!
I want to check if a particular entry has proper entry.
lets say my “id” is integer for the 2nd loop and i give a string entry it shud show me error saying 2nd entry shud be int not a string(i tried including for loop)it isnt working
@danny-dainton can you please help me with this
[
{
"id": 108,
"status": "open",
"cam_reports": [
{
"id": "A1S1",
"status": "open"
}
],
"date": 1597116599557
},
{
"id": 1082,
"status": "open",
"cam_reports": [
{
"id": "A7S2",
"status": "open"
}
],
"date": 1596775719
},
{
"id": 1083,
"status": "open",
"cam_reports": [
{
"id": "A7S3",
"status": "open"
}
],
"date": 1596775720
},
Hey @sadiyadiya02.sd
Welcome to the community! 
You could loop through the response and check the id type like this:
pm.test("Check id is an number", () => {
_.each(pm.response.json(), (arrItem) => {
console.log(arrItem.id)
pm.expect(arrItem.id).to.be.a('number')
})
})
I’ve using the lodash .each() function to loop over the response data and then checking that the id is a number. There’s a console.log() statement there so you can see the values.
You mentioned id but as there are 2 in that object, which is the one you wanted to do the check against?
This looks horrible but it would work if you wanted to check the id inside the cam_reports array:
pm.test("Check id is an number", () => {
_.each(pm.response.json(), (arrItem) => {
_.each(arrItem.cam_reports, (report) => {
console.log(report.id)
pm.expect(report.id).to.be.a('number')
})
})
})
1 Like
I’m not sure I know what that means - Can you provide an example please.
What have you tried and what isn’t currently working for you?
I don’t really understand what you mean.
You’re using a schema validation test in a for loop?
_ is deprecated so use require(‘lodash’)
const _ = require('lodash')
pm.test("Check id is an number", () => {
_.each(pm.response.json(), (arrItem) => {
_.each(arrItem.cam_reports, (report) => {
console.log(report.id)
pm.expect(report.id).to.be.a('number')
})
})
})