Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsonpath find all object(restassured)

This is my JSON :

[
{
    "id": 9741962,
    "name": "getName",
    "isActive": true
},
{
    "id": 1,
    "name": "New",
    "isActive": true
}
]

I want to get all the object that has the name :getName using jsonPath how can I do it using JsonPath (the onw that comes with rest assured)

I try this one

JsonPath.with(jsonResponse).get("findAll { a -> a.name == getName  }");

but I am getting Error.

java.lang.IllegalArgumentException: No such property: sdfsdf for class: Script1

Thanks.

like image 254
Michael Biniashvili Avatar asked Sep 06 '25 19:09

Michael Biniashvili


2 Answers

OK I found it, needed to add apostrophes.

JsonPath.with(jsonResponse).get("findAll { a -> a.name == 'getName' }");

like image 85
Michael Biniashvili Avatar answered Sep 10 '25 00:09

Michael Biniashvili


You need to set param. Try

JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name  }")
like image 32
Syam S Avatar answered Sep 09 '25 23:09

Syam S