-
I am validating an api response that has a format as shown below: {
"results": [
{
"id": 3,
"name": "a"
},
{
"id": 4,
"name": "d"
},
{
"id": 3,
"name": "Z",
"size": {
"length": 5,
"width": 4
}
}
]
} "size" object node is not present on all array elements. I am writing a test (using Built-in Filters) to give me the "length" of first element where "size" object is present. I was hoping this would work : " json.results | filter(size > 0) | at(0).size.length" "equal" 5 . But is failing. Any idea why? It looks like "json.results | filter(size > 0)| at(0)" is giving me expected results. Or is there a better approach to test this response? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @nikhilp79 You dont need built in filter for this. Use this expression in tests left input for Docs here |
Beta Was this translation helpful? Give feedback.
Hi @nikhilp79 You dont need built in filter for this.
Use this expression in tests left input for
json query
-json.results[size>0][0].size.length
Docs here
https://github.com/rangav/thunder-client-support/blob/master/docs/testing.md#test-arrays