My JSON Response reads something like:
{
"_embedded":{
"contents": [
{
"data": 1234,
"success": true,
}
]
}
}
I am attempting to extract the the success message and data. However my console output keeps reading null.
Once extracting the Response here is my code that receives a Null response using Rest Assured:
String res = response.asString():
JsonPath js = new JsonPath(res);
String success = js.get("_embedded[0].contents[0].success");
String data = js.get("_embedded[0].contents[0].data");
System.out.println(success);
System.out.println(data);
My response for both success and data is null
From your JSON sample, it looks like _embedded is not a list. _embedded[0] might return null because there is no list named _embedded when you try to extract the success value using "_embedded[0].contents[0].success".
Extract the success value by using
js.get("$._embedded.contents[0].success");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.