0

After my RestAssured code executed, I got a response body like this(which is valid, since I verified it in Postman also)

[
    {
        "team": null,
        "name": "Automation",
        "id": "977638c2-0095-42fb-a3fb-3ef442cc61e2"
    },
    {
        "team": null,
        "name": "Default",
        "id": "e9e0ab5d-0abf-402a-a747-612a4e9c7e25"
    }
]

Now I need to retrieve the id of a Json object for which the name is 'Automation'. The line of code I wrote is like this which is returning null, which I can't understand.

response.path("$.find{it.name == 'Automation'}.id");  (OR)
response.path("content.find{it.name == 'Automation'}.id");

Please correct my code, to return the correct value 977638c2-0095-42fb-a3fb-3ef442cc61e2

PraNuta
  • 629
  • 3
  • 12
  • 33

1 Answers1

1

You can use the query like this:

response.path("find{it.name == 'Automation'}.id");
Alexey R.
  • 8,057
  • 2
  • 11
  • 27
  • 1
    Awesome ! It worked. Looks like I tried to over engineer it. lol! – PraNuta Sep 02 '22 at 13:56
  • I thought, I should start with the root which is represented by either 'content' or '$'. I could not imagine, that is optional. – PraNuta Sep 02 '22 at 14:14