Fetch ID of first response RestAssured

Viewed 21

I am getting many responses via GET http request but I only want to fetch the ID of first student which I got in response how to do it in Rest Assured.

  [
    {
        "id": 14114,
        "name": "Pragyanshii",
        
    },
    {
        "id": 14119,
        "name": "ankit",
        
    },
    {
        "id": 14122,
        "name": "varun",
    }
  ]

I want to fetch id: 14114

1 Answers

This is one way to achieve your goal.

Response response = ...;
int id = response.jsonPath().get("[0].id");
System.out.println(id); //14114
Related