'I am getting an error "Failed to parse the JSON document", I have used JsonPath
//Get place
{
String getPlaceResponse = given().log().all().queryParam("key", "qaclick123").queryParam("place_id", placeId )
.when().get("maps/api/place/update/json")
.then().assertThat().log().all().statusCode(200).extract().response().asString();
System.out.println(getPlaceResponse);
JsonPath js1 = new JsonPath(getPlaceResponse);
String actualAddress = js1.getString("address");
System.out.println(actualAddress);
}
Json document:
Body:
{
"location": {
"lat": -381.383494,
"lng": 33.427362
},
"accuracy": 50,
"name": "Frontline house",
"phone_number": "(+91) 983 893 3937",
"address": "29, side layout, cohen 09",
"types": [
"shoe park",
"shop"
],
"website": "http://google.com",
"language": "French-IN"
}
//errors//
Exception in thread "main" io.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document
at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1002)
at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967)
at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047)
at io.restassured.path.json.JsonPath.get(JsonPath.java:202)
at io.restassured.path.json.JsonPath.getString(JsonPath.java:352)
at basic.Basic1.main(Basic1.java:62)
Caused by: java.lang.IllegalArgumentException: The JSON input text should neither be null nor empty.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:72)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:277)
at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:80)
at io.restassured.path.json.JsonPath$4$1.method(JsonPath.java:965)
at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1000)
... 5 more
Solution 1:[1]
delete the following and check onces
System.out.println(getPlaceResponse);
JsonPath js1 = new JsonPath(getPlaceResponse);
String actualAddress = js1.getString("address");
System.out.println(actualAddress);
there is no error in your program.
when you are copying json there might be some issue that all.
Solution 2:[2]
You used json path so only u got that error. Then how it will be converted when you are running the program.
Copy it in the program then you will json formate conversation in eclipse.
It won’t accept json formate directly.
Solution 3:[3]
Use resource maps/api/place/get/json
instead of maps/api/place/update/json
. We are getting the data right.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | procrastinator |
Solution 2 | Venkat Bobby |
Solution 3 | blackgreen |