Closed niclash closed 9 years ago
This was actually a bug in releases prior to v1.0.
I'm aware that some people depended on this and I understand that it is useful in some cases. The problem is that from a JSONPath perspective it does not make sense. The last part [0]
in your path2
does not correspond to a path in the document. What would the result be if you executed the query with the AS_PATH_LIST
option? It does not exist.
I am considering to add some kind of pipe support. Then the path would be:
"$.blocks[?(@.name=='AQ')].edges[?(@.name=='value')].value | [0]"
or
"$.blocks[?(@.name=='AQ')].edges[?(@.name=='value')].value -> [0]"
but I'm not there yet.
I see.... as clear as mud. To see if I understand this correctly; I assumed that every operator, worked on the "resultset" of the previous operator (left and possibly some precedence rules). And in reality, the operators work like filters over the document structure before the evaluation of each operator. Right?
Also, instead of "pipe" character, a "valueof()" would be better to allow precedence, example;
$($.blocks[?(@.name=='AQ')].edges[?(@.name=='value')].value)[0]
Prior to version 1.0 it worked the way you described (operating on the previous resultset). The evaluation kept going until the path contained no more tokens. This was not efficient and has been reworked. Yes, the new evaluation could be described like that.
Consider the following example:
{
"c": {
"d1": {
"url": [ "url1", "url2" ]
},
"d2": {
"url": [ "url3", "url4","url5" ]
}
}
}
and the expression $.c.*.url[2]
. It fails with an "index out of bounds" error even though there is one element that fits the path. Is that expected?
@dornatsky it's a bug but it's not related to this issue. I have created a new issue #79.
@kallestenflo Have you introduced this pipe mechanism or something similar yet?
No, not yet.
There is a regression in 1.2.0 from 0.9.1, where a complex input document and expression simply doesn't agree correctly.
The code is found below, and the exception shows that it misunderstands the Array situation of the "[0]" in "path2", although it clearly extracts a JSONArray in if I remove the "[0]" as seen in the code below.
Exception in thread "main" com.jayway.jsonpath.InvalidPathException: Filter: [0] can only be applied to arrays. Current context is: 51.968503937007874 at com.jayway.jsonpath.internal.token.ArrayPathToken.evaluate(ArrayPathToken.java:60) at com.jayway.jsonpath.internal.token.PathToken.handleObjectProperty(PathToken.java:71) at com.jayway.jsonpath.internal.token.PropertyPathToken.evaluate(PropertyPathToken.java:44) at com.jayway.jsonpath.internal.token.PathToken.handleArrayIndex(PathToken.java:125) at com.jayway.jsonpath.internal.token.PredicatePathToken.evaluate(PredicatePathToken.java:67)