I have a below JSON. I want to get pin code where street =='abc strt.'
I am using Jaway to achieve this.
{
"studentId": "10001",
"studentSection": "A",
"address": [
{
"street": "abc strt.",
"pincode": "00000000"
},
{
"street": "xzy strt.",
"pincode": "1111111"
},
{
"street": "678 strt.",
"pincode": "8765"
},
{
"street": "ity strt.",
"pincode": "234567"
}
]
}
List<String> = result = JsonPath.read(json, "$.['address'].[?@.street == 'abc strt.'].pincode");
JayWay XPath: $.['address'].[?@.street == 'abc strt.'].pincode
, it's returning List<String>
.
The above query will always return a single value, but due to the return type as List<String>
, I have to use value as list.get(0)
.
Is there a way to return String instead of List??
Also, I have 10 more queries, which I have to execute on the same JSON. Should I query once & use the result, or can I query 10 times and use the result. What is the preferred way to do this?