4

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.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Michael Biniashvili
  • 500
  • 1
  • 12
  • 24

2 Answers2

7

OK I found it, needed to add apostrophes.

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

iguanito
  • 13
  • 3
Michael Biniashvili
  • 500
  • 1
  • 12
  • 24
2

You need to set param. Try

JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name  }")
Syam S
  • 8,421
  • 1
  • 26
  • 36