How to extract the whole JSON response as a string in Rest Assured?

Rest AssuredDynamic ProgrammingProgramming

We can extract the whole JSON as a string in Rest Assured. This is achieved with the help of the extract method. It shall extract the whole response as a string using the asString method.

We shall send a GET request via Postman on a mock API, observe the Response.


Using Rest Assured, we shall get the whole response in string format.

Code Implementation

import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import io.restassured.RestAssured;
public class NewTest {
   public void getResponseAsString() {

      //base URL
      RestAssured.baseURI = "";

      String r = RestAssured.given().when()

      //get request

      //get response as string



Updated on 17-Nov-2021 12:06:27