Reputation: 428
I want to use RestAssured to test an endpoint that returns a JSON list of objects. How can I verify the contents of the last object in the list using RestAssured JsonPath?
Example return value:
[
{
"foo": "bar"
},
{
"foo": "brazz"
}
]
I tried using negative indices:
body("[-1].foo", equalTo("brazz"))
but that does not work, as Rest assured considers "[-1].foo"
to be an empty list.
How can I access the last element of a list with JsonPath Syntax?
Upvotes: 0
Views: 966
Reputation: 5917
Yes, you can use last()
to get the last item.
body("last().foo", equalTo("brazz"))
Upvotes: 1