GET METHOD with Key and Values pair combination PART-2

This is my second blog in the series. Part 1 covered GET Method with RestAssured.

In order to test and validate the API with RestAssured sometimes it is needed to have sequential combination keys and values from Json Response of TESTAPI.

I have used the API

In this API with Get Method and status code of 200, this is the Response

{“page”:2,”per_page”:6,”total”:12,”total_pages”:2,”data”:[{“id”:7,”email”:””,”first_name”:”Michael”,”last_name”:”Lawson”,”avatar”:”"},{"id":8,"email":"","first_name":"Lindsay","last_name":"Ferguson","avatar":""},{"id":9,"email":"","first_name":"Tobias","last_name":"Funke","avatar":""},{"id":10,"email":"","first_name":"Byron","last_name":"Fields","avatar":""},{"id":11,"email":"","first_name":"George","last_name":"Edwards","avatar":""},{"id":12,"email":"","first_name":"Rachel","last_name":"Howell","avatar":""}],"support":{"url":"","text":"To keep ReqRes free, contributions towards server costs are appreciated!”}}

Now to extract the ID which is basically a Key and Values from this Json Values are First_name and Last_Name and Email. Which is related to a single key Id


Advantages: This method is very useful when you want to get the values from API response in KEY -VALUE pair fashion.

Special Features: This method is also used to extract multiple field values associated with a single key with Package org.apache.commons.collections4

This package contains the interfaces and utilities shared across all the sub-packages of this component.

Testing and Validation: Mapping from one key to multiple field values.

Tools required: JAVA, Eclipse IDE or Intelli J with Maven, and TestNG Plugin.

Steps to execute:

1. Create a Maven Project in the Eclipse IDE.

2. TestNg plug-in must be installed. You can install from Marketplace or add a dependency.

3. In the POM.Xml add dependencies for RestAssured and Json .Visit the official page to import those dependencies. I have used RestAssured 4.3.1 also added more dependencies for “Guava-Libraries”.






4. I have used the “Package org.apache.commons.collections4” from here:

Package org.apache.commons.collections4

This package contains the interfaces and utilities shared across all the sub-packages of this component.

I used the interface MultiMap .<Keys, Values>

<Keys> Reference Keys

<Values> Associated with reference keys.

Used this Deprecated.

since 4.1, use MultivalueMap instead.

@Deprecatedpublic interface MultiMap<K,V>extends IterableMap<K,Object>

**Defines a map that holds a collection of values against each key.

A MultiMap is a Map with slightly different semantics. Putting a value into the map will add value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key.


My POM.XML looks like this with added dependencies.


<! —


































Code Breakdown:

· Response myresponse=RestAssured.get(“");

· String mystringid =myresponse.jsonPath().getString(“”);

o I have stored all the id from API in mystringid.

· String myfirst_name =myresponse.jsonPath().getString(“data.first_name”);

· String mylast_name=myresponse.jsonPath().getString(“data.last_name”);

· String myemail =myresponse.jsonPath().getString(“”);

6.To split the string at “,”.

String str[] =myfirst_name.split(“,”);

String str1[] =mylast_name.split(“,”);

String str2[] =myemail.split(“,”);

String str3[]= mystringid.split(“,”);

7.Converted String Array to subsequent List in these easy steps.

List<String> flist = Arrays.asList(str);

List<String> llist = Arrays.asList(str1);


8 Now we have the list of Firstname and Lastname and Email.Used this MultivalueMap to map each key to different field Values.

Deprecated Version 4.1

MultiValueMap<String,String>hmap=new MultivalueMap<String,String>();

9.Used this for 6 records of each Id,Firstname and Last name and Email.

Method: Hmap.put(key,Value) This is to place values with key and vale in the Hmap.

Hmap.put(key,Value) is used and in the values for firstname list and Lastname List and Emaillist is passed.

For Loop.

Here in the API 6 Records Each for Keys and Values.

· for( int i=0 ; i<6 ; i++)






The Full code for methodKeymappedtoMultipleValues is here:

GET METHOD with Single Key and multiple Values

I have used these imports in my method.

My Console-Output is :

Let me know your feedback and what would you like to hear more.

See you in other methods of API Testing!

Reference: Rest

Mani Bhute

Completed on 02/09/2021

Mani has done Masters in Electronics and currently working in IT Automation SDET .Her area of specialization in Java ,Selenium ,Katalon, REST API ,RestAssured.