I have the following Get request:
{
"threats": [
{
"category": "port-scan",
"details": "00:15:5d:9b:1f:18",
"blocks": 1
},
{
"category": "whitelist-violation",
"details": "4.4.3.4",
"blocks": 1
},
{
"category": "whitelist-violation",
"details": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"blocks": 1
},
{
"category": "attack-on-device",
"details": "1.2.3.4",
"blocks": 1
},
{
"category": "attack-on-device",
"details": "5.2.3.5",
"blocks": 1
},
{
"category": "brute-force",
"details": "aa:aa:aa:aa:aa:aa_23",
"blocks": 1
}
],
"byCategory": [
{
"label": "brute-force",
"value": 1,
"pcnt": 0.16666666666666666
},
{
"label": "whitelist-violation",
"value": 2,
"pcnt": 0.3333333333333333
}
],
"limit": 100
}
I want to ckeck values in arrays, but the response of values in the array is always floating. So I cant check it in a fixed way like this
let jsonDataResult = pm.response.json();
pm.test("Array values", function () {
var jsonDataResult = pm.response.json();
pm.response.to.have.status(200);
//Check threats
pm.expect(jsonDataResult.threats[0].details).to.eql("00:15:5d:9b:1f:18");
pm.expect(jsonDataResult.threats[0].blocks).to.eql(1);
pm.expect(jsonDataResult.threats[0].category).to.eql("port-scan");
pm.expect(jsonDataResult.threats[1].details).to.eql("4.4.3.4");
pm.expect(jsonDataResult.threats[1].blocks).to.eql(1);
pm.expect(jsonDataResult.threats[1].category).to.eql("whitelist-violation");
// And so on...
});
Sometimes response is the following
"threats": [
{
"category": "brute-force",
"details": "aa:aa:aa:aa:aa:aa_23",
"blocks": 1
},
{
"category": "attack-on-device",
"details": "5.2.3.5",
"blocks": 1
},
{
"category": "whitelist-violation",
"details": "4.4.3.4",
"blocks": 1
},
{
"category": "whitelist-violation",
"details": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"blocks": 1
},
{
"category": "attack-on-device",
"details": "1.2.3.4",
"blocks": 1
},
{
"category": "port-scan",
"details": "00:15:5d:9b:1f:18",
"blocks": 1
}
],
"byCategory": [
{
"label": "brute-force",
"value": 1,
"pcnt": 0.16666666666666666
},
{
"label": "whitelist-violation",
"value": 2,
"pcnt": 0.3333333333333333
},
{
"label": "port-scan",
"value": 1,
"pcnt": 0.16666666666666666
},
{
"label": "attack-on-device",
"value": 2,
"pcnt": 0.3333333333333333
}
],
"limit": 100
}