I am new to API automation. Here is my JSON structure. I want to extract the "LunId" from all the 3 arrays. Path is mentioned in the code.
Error1:
Error2:
@Test
public void getAllLuns(){
Response resp = given().header("Authorization", "Bearer "+"ddnsdndnn22x");
when().
get("http://10.100.242.11/api/v1/luns");
String Name = resp.
then().
contentType(ContentType.JSON).
extract().
path("$..LunId").toString();
System.out.println("Lun Name is--->"+LunId);
I am extracting the correct data in JSON path Extractor online, but while running it in eclipse it gives me an error. Problem is in the path. Please help, how to work with these kinds of paths. Getting Error1- when using"$" in the path and Error2 when not using it.
This can easily be done using JSONPath Lib
https://github.com/json-path/JsonPath
public List<String> getLunIDNames() {
return lunIDNamess = JsonPath.read("ValidJSON", "$..LunId[*].Name");
}
Hope this helps
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.