I recently ran into a surprising result when querying a json string using the JsonPath library. When I use a deep scan (..) to query for an element in an array, the matching element gets returned twice in the results. For example, if I have a json document like:
{
"container": [
{
"id": "1",
"name": "foo",
"value": "bar"
},
{
"id": "2",
"name": "hello",
"value": "world"
}
]
}
and I query for the value of the element with name "hello" using
List actual = JsonPath.read(jsonTwo,"$..*[?(@.name=='hello')].value");
I get the result
["world","world"]
I realize this is a trivial example and deep scan is overkill. However this is still an unexpected result. Is this a bug or intended behaviour? If it is intended, how do I avoid duplicate results when using a deepscan?