I am trying to extract list of string from following Json
"example":{[
{"@name":"name1"},
{"@name":"name2"},
{"@name":"name3"},
{"@name":"name4"}
]}
I want to get the list of @name values. I am using jayway jsonpath to do this.
I tried the following code,
List<String> response = null;
try{
ReadContext ctx = JsonPath.parse(data);
response = ctx.read(xPath);
}catch(Exception e){
AppLogger.EventLogger.error(e.getMessage());
response = null;
}
return response;
but got an exception saying could not find the specified path. I have used the following jsonPath example.@name
Can someone tell me What went wrong in my code? how to extract list @name values.
Expected output :
[name1,name2,name3,name4]