I've got a json like that
{
"accounts": {
"7-PIGGY_BANK-2739": {
"timestamp": "2023-07-11T14:08:23.327",
"state": "PRODUCT_ACTUAL",
"entitySubSystems": "CFT",
"number": "2739",
"entityType": "PIGGY_BANK",
"entityId": "2739",
"entityLocalId": "2739"
},
"17-CREDIT_CARD_ACCOUNT-1687": {
"timestamp": "2023-07-11T14:08:22.81",
"state": "PRODUCT_ACTUAL",
"entitySubSystems": "OPENW",
"number": "1687",
"entityType": "CREDIT_CARD_ACCOUNT",
"entityId": "1687",
"entityLocalId": "1687"
}
},
"deposites": {
"7-DEPOSIT-0495": {
"timestamp": "2023-07-11T14:08:23.327",
"state": "PRODUCT_ACTUAL",
"entitySubSystems": "CFT",
"number": "0495",
"entityType": "DEPOSIT",
"entityId": "4495",
"entityLocalId": "20495"
}
},
"cards": {
"17-DEBET_CARD-07820": {
"timestamp": "2023-07-11T14:08:22.809",
"state": "PRODUCT_ACTUAL",
"entitySubSystems": "OPENW",
"number": "07820",
"entityType": "DEBET_CARD",
"entityId": "40367",
"entityLocalId": "07820"
}
}
}
I want to check what "entitySubSystems" and some other parameters are inside response. The problem is that the names of objects inside blocks are different. They depend on the clients id.
In the end I want to have a test like that. "CFT - Piggy_Bank test" Passed if there is at least one account.
How to corretly parse it for such test? Or it's hardly or even impossible?)
I thied forEach but it didn't work properly because of different names.
You can do it without looping and it's not difficult at all.
In JavaScript, you can check whether JSON object has any key using below code.
Object.keys(your_object)
You can use it to match your requirement as below:
pm.test("CFT-Piggy_Bank_Atleast_One_Acc", function () {
pm.expect(Object.keys(pm.response.json().accounts).length).to.greaterThan(0);
});