Skip to main content

Iterating over JSON Array Elements using JsonPath in REST Assured

Iterating over JSON Array is same as you iterate using loops on other Array elements. There is nothing special you need to do. Check below example: 

public class ReqRes 
	public static String id = "2";
	public void setup()
		RestAssured.baseURI = "";
		RestAssured.basePath = "api";
	public void IterateJSONArray()
		Response res = given()
			.queryParam("page", "2")
		JsonPath js = new JsonPath(res.asString());
		int size = js.getInt("data.size()");
		System.out.println("size is: "+size);
		for(int i = 0; i < size; i++)

In above example you can see we have pass the index of array inside getString method using String concatenation and print out the result.

Video Tutorial


Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.