Validating a JSON response if a value is not.eql to 0?

Hello, I am trying to confirm via pm.test if the “value” that is returned in " “name”: “Guarantee” " doesn’t equal 0(zero), can someone please help, how to properly make the request?

Here is my response:

{
    "id": 0,
    "principalSum": 1000.000000,
    "instalments": [
        {
            "id": 0,
            "paymentNumber": 1,
            "instalmentDate": "2021/10/18",
            "instalment": 144.370000,
            "instalmentAmount": 144.370000,
            "principal": 69.140000,
            "interest": 33.330000,
            "daysDelay": 3,
            "instalmentDay": null,
            "paidSum": 0.0,
            "productAccruals": [
                {
                    "id": 1,
                    "accrualId": 1,
                    "name": "Principal",
                    "value": 69.140000,
                    "interestPercent": null,
                    "isPartApr": true
                },
                {
                    "id": 6,
                    "accrualId": 6,
                    "name": "Interest",
                    "value": 33.330000,
                    "interestPercent": null,
                    "isPartApr": true
                },
                {
                    "id": 17,
                    "accrualId": 17,
                    "name": "Guarantee",
                    "value": 41.900000,
                    "interestPercent": null,
                    "isPartApr": false
                }
            ],
            "instalmentDiscount": 0.0,
            "instalmentAmountWithDiscount": 144.370000
        },
        {
            "id": 0,
            "paymentNumber": 2,
            "instalmentDate": "2021/10/25",
            "instalment": 144.370000,
            "instalmentAmount": 144.370000,
            "principal": 71.440000,
            "interest": 31.030000,
            "daysDelay": 0,
            "instalmentDay": null,
            "paidSum": 0.0,
            "productAccruals": [
                {
                    "id": 1,
                    "accrualId": 1,
                    "name": "Principal",
                    "value": 71.440000,
                    "interestPercent": null,
                    "isPartApr": true
                },
                {
                    "id": 6,
                    "accrualId": 6,
                    "name": "Interest",
                    "value": 31.030000,
                    "interestPercent": null,
                    "isPartApr": true
                },
                {
                    "id": 17,
                    "accrualId": 17,
                    "name": "Guarantee",
                    "value": 41.900000,
                    "interestPercent": null,
                    "isPartApr": false
                }
            ],
            "instalmentDiscount": 0.0,
            "instalmentAmountWithDiscount": 144.370000
        },

the response continues the same way until “paymentNumber”: 12 for example.
We need only for the first one to confirm.

Hey @parsy2

I did it like this but there will be a more straightforward solution:

/* Gets the first response data and the first object in the instalments array which has an array called productAccuruals. 
Then filter that array to return the one that has the correct name. 
*/  
let productAccruals = _.get(jsonData, 'instalments.0.productAccruals'),
    item = productAccruals.filter(e => e.name === 'Guarantee');

// This test it using the first object in the array and checking that the value is above zero.
pm.test('Value above zero', () => {
    pm.expect(item[0].value).to.be.above(0);
})

image

I have no idea what the response was from that request :laughing:

My solution is based on your example response code. If that didn’t match this request’s response and the structure is different or a certain property isn’t there, the test code is going to fail.