[go: up one dir, main page]

0% found this document useful (0 votes)
16 views1 page

Parsing Json

The document is a Java class that uses RestAssured to perform a GET request to the Google Maps API for nearby places of a specified type. It verifies the response status code and content type, then parses the JSON response to extract and print the names of the results. The test is structured using TestNG annotations for execution.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Parsing Json

The document is a Java class that uses RestAssured to perform a GET request to the Google Maps API for nearby places of a specified type. It verifies the response status code and content type, then parses the JSON response to extract and print the names of the results. The test is structured using TestNG annotations for execution.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package rest.basic.

testing;

import static io.restassured.RestAssured.given;


import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

public class ParsingJson {

@Test
public void verifyResponse(){

RestAssured.baseURI = "https://maps.googleapis.com";

Response res = given().


param("location", "-33.8670522,151.1957362").
param("radius", "500").
param("type", "cruise").
param("key", "AIzaSyB-ZliaFkPtyfykn7E2nW2yxgBPAvRVUMo").
log().all().

when().
get("/maps/api/place/nearbysearch/json").

then().assertThat().statusCode(200).and().
contentType(ContentType.JSON).
log().all().

extract().response();

String response = res.asString();

JsonPath jsonRes = new JsonPath(response);

int arrSize = jsonRes.getInt("results.size()");

for (int i = 0; i < arrSize; i++) {


String name = jsonRes.getString("results["+i+"].name");
System.out.println(name);
}
}
}

You might also like