

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract the whole JSON response as a string in Rest Assured?
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.
Example
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 { @Test public void getResponseAsString() { //base URL RestAssured.baseURI = "https://run.mocky.io/v3"; String r = RestAssured.given().when() //get request .get("/cd3a7e12-9057-4b51-bf2d-a2d4e2ddad8d") //get response as string .then().extract().response().asString(); System.out.println(r); } }
Output
- Related Questions & Answers
- How to verify JSON response headers in Rest Assured?
- How to verify a JSON response body using Assertions in Rest Assured?
- How to parse a JSON response and get a particular field from the response in Rest Assured?
- Explain how to get the size of a JSON array response in Rest Assured.
- How to validate XML response in Rest Assured?
- How to use Assertion in response in Rest Assured?
- How to get the response time of a request in Rest Assured?
- How to validate the response time of a request in Rest Assured?
- How to transform the response to the Java list in Rest Assured?
- How to handle static JSON in Rest Assured?
- Validate JSON Schema in Rest Assured.
- How to get a JSON field in a nested JSON using Rest Assured?
- How to incorporate TestNG assertions in validating Response in Rest Assured?
- What is JSON parsing in Rest Assured?
- How to get a JSON array field in a nested JSON using Rest Assured?
Advertisements