What is API :
An application-programming interface (API) is a set of programming instructions and standards for accessing a Web-based software application or Web tool.

Example :

An API is a software-to-software interface, not a user interface. With APIs, applications talk to each other without any user knowledge or intervention. When you buy movie tickets online and enter your credit card information, the movie ticket Web site uses an API to send your credit card information to a remote application that verifies whether your information is correct. Once payment is confirmed, the remote application sends a response back to the movie ticket Web site saying it’s OK to issue the tickets.

What is JSON :

JSON (JavaScript Object Notation) is a lightweight, text-based, language-independent data exchange format that is easy for humans and machines to read and write. JSON can represent two structured types: objects and arrays. An object is an unordered collection of zero or more name/value pairs. An array is an ordered sequence of zero or more values. The values can be strings, numbers, booleans, null, and these two structured types.

Example : You can see it here.

JSON is an easier-to-use alternative to XML.

Note : Here i am just conferring how to parse and How to convert JsonObject to Java Object.So that you could use it your live projects using selenium.
Application contentType : Json

Objective : To validate Address : Chicago, IL, USA.
GoogleMaps API :

We can easily parse Json using “json-lib-2.4-jdk15.jar” Download from here…!

Please consider the below code as a reference.

import java.util.Scanner;

import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class ReadJsonObject{
public void aptTesting() throws Exception {
try {
URL url = new URL(”);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty(“Accept”, “application/json”);

if (conn.getResponseCode() != 200) {
throw new RuntimeException(” HTTP error code : ”
+ conn.getResponseCode());

Scanner scan = new Scanner(url.openStream());
String entireResponse = new String();
while (scan.hasNext())
entireResponse += scan.nextLine();

System.out.println(“Response : “+entireResponse);


JSONObject obj = new JSONObject(entireResponse );
String responseCode = obj.getString(“status”);
System.out.println(“status : ” + responseCode);

JSONArray arr = obj.getJSONArray(“results”);
for (int i = 0; i < arr.length(); i++) {
String placeid = arr.getJSONObject(i).getString(“place_id”);
System.out.println(“Place id : ” + placeid);
String formatAddress = arr.getJSONObject(i).getString(
System.out.println(“Address : ” + formatAddress);

//validating Address as per the requirement
if(formatAddress.equalsIgnoreCase(“Chicago, IL, USA”))
System.out.println(“Address is as Expected”);
System.out.println(“Address is not as Expected”);

} catch (MalformedURLException e) {

} catch (IOException e) {




That’s it, Now you know to convert JsonObject to Java Object and use it in your Selenium snippet.

You can Practice using API :

Wanna know about basics? Click Here for Basics

Smart way of Rest API Testing using Selenium Webdriver will be posted soon.


  1. Thanks for the post.

  2. From what I know, today REST API technology is very often used. I really like using native applications that work in the cloud and I've read quite a lot about them. The more that this solution is now very popular.