REST Assured Iterating Over JSON Array: how to select randomly an email from the email list

Query:  Hi! Thanks for your tutorial.
Based on this example, I have a question -> After getting all emails, how to select randomly an email from the email list? Hope to receive your reply. Thank you!

User: caocao cup

Source: Youtube ProgramsBuzz

Video Title: Iterating over JSON Array Elements using JsonPath in REST Assured

Video URL:

Hi there,

You can get a random mail out the list using :

  • ArrayList and Random from javautils
  • Store the loop iteration of the email list into the array list we declared outside.
  • With the use of Random util we can get the random mail out of the list.
	public void ArrayIterate()
		Random r = new Random();
		ArrayList<String> ar = new ArrayList<String>();
		Response res = 
//			.queryParam("page", "2")

		JsonPath js = new JsonPath(res.asString());
		int size = js.getInt("data.size()");
		for(int i = 0; i < size; i++)
			String emailList = js.getString("data["+i+"].email");