How to get a value from a nested list in Rest Assured?

Rest AssuredDynamic ProgrammingProgramming

We can get a value from a nested list in Rest Assured. This is done with the help of the extract method. To grab the item, we have to use the path method(after the extract method) and pass the item in the response we want to obtain.

We shall first send a GET request via Postman on a mock API URL and go through its Response having a nested list.


Code Implementation

import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import java.util.ArrayList;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
public class NewTest {
   public void getRequest() {

      //base URL
      RestAssured.baseURI = "";
      RestAssured.basePath =

      //response from GET request

      //extract values from Response
      String name = given().contentType(ContentType.JSON).get()
      String age = given().contentType(ContentType.JSON).get()

      //extract values from a nested list in Response
      ArrayList<String> s = given().contentType(ContentType.JSON).get()
      for(String subject: s) {


Updated on 22-Nov-2021 10:02:42