I'm currently trying to parse precisely a JSON response (using POSTMAN).
The JSON response has the following structure (I use ... to skip irrelevant info):
*
{
"href": ...,
"offset": ...,
"limit": ...,
"first": ...,
"last": ...,
"entries": [
{
"href": ...,
"id": ...,
"name": "MY_FIRST_ITEM_NAME",
"tags": [
...,
...
],
"objectClass": [
...
],
"attributes": {
...,
...,
...,
"device.type": "MY_ITEM_TYPE,
...
},
...
},
{
"href": ...,
"id": ...,
"name": "MY_SECOND_ITEM_NAME",
"tags": [
...,
...
],
"objectClass": [
...
],
"attributes": {
...,
...,
...,
"device.type": "MY_ITEM_TYPE,
...
},
...
},
...
]
}*
I want to test several known values: tests["test first item"] = responseBody.has("MY_FIRST_ITEM_NAME") this works, but I also want to check the associated device type if I use responseBody.has("MY_ITEM_TYPE") I can't figure out to which item it is related to, so I try to make a more precise checking: *
tests["test entries 0"] = body.entries[0].name === "MY_FIRST_ITEM_NAME"*;
this works but when it comes to test the device type:
tests["test entries 0"] = body.entries[0].attributes.device.type
it ends up with an error "TypeError: Cannot read property 'type' of undefined"
With the console I can see the attributes (doing console.log(body.entries[0].attributes);) but it is not possible to go one step deeper. Is it a postman limitation ? is there another way to reach precisely this device.type information ?
Thank you for help
Alexandre