- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain how to get the size of a JSON array response in Rest Assured.
We can get the size of a JSON array response in Rest Assured. First, we shall obtain a Response body which is in JSON format from a request. Then convert it to string. Finally, obtain its length with the size method. Code Implementation
import static io.restassured.RestAssured.given; import org.testng.annotations.Test; import io.restassured.RestAssured; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; public class NewTest { @Test public void jsonAryLen() { //obtain Response from GET request Response res = given() .when() .get("https://jsonplaceholder.typicode.com/posts"); //convert JSON to string JsonPath j = new JsonPath(res.asString()); //length of JSON array int s = j.getInt("data.size()"); System.out.println( s); } }
Output
- Related Articles
- How to get the size of an array within a nested JSON in Rest Assured?
- How to parse a JSON response and get a particular field from the response in Rest Assured?
- How to verify JSON response headers in Rest Assured?
- How to get a JSON array field in a nested JSON using Rest Assured?
- How to verify a JSON response body using Assertions in Rest Assured?
- How to get the response time of a request in Rest Assured?
- How to extract the whole JSON response as a string in Rest Assured?
- How to get a JSON field in a nested JSON using Rest Assured?
- How to validate XML response in Rest Assured?
- How to validate the response time of a request in Rest Assured?
- How to use Assertion in response in Rest Assured?
- How to handle static JSON in Rest Assured?
- How to transform the response to the Java list in Rest Assured?
- How to get JSON fields(nodes) based on conditions using Rest Assured?
- How to iterate through and access the JSON array elements using Rest Assured?

Advertisements