-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semantics of the list form of descendant selector #232
Comments
I propose the following actions:
Any objections? |
I don't think you can tell about the ordering from this result, the query is flagged with footnote 4, see (https://cburgmer.github.io/json-path-comparison/#union_with_keys_after_recursive_descent), which indicates that these results are being sorted before comparison. A quick check shows that a number of implementations that fall in the consensus (including Goessner JavaScript) actually return
|
@danielaparker well spotted (and thanks for raising cburgmer/json-path-comparison#118). So that leaves the following proposed actions:
|
That sounds complicated :-) One thing to keep in mind is that implementations that return
do not do anything complicated, nor do they "reorder a subsequence of the nodes in an array-sequenced preorder". Rather, they simply apply the selector |
I agree it sounds complicated. Perhaps, along the lines you describe, it is best to describe the possible orderings of descendants and then say how particular descendant selectors are apply to those descendants. |
It may be helpful to think of the recursion operator First, create a new empty result list. Then
This becomes the new current result list. So if the current result list contains the root value
the recursive operation produces
Then applying the selector
|
I'd prefer to define the orderings of the descendants in terms of a postcondition rather than an algorithm because that avoids implementation bias - a useful property for a spec. Sometimes the postcondition form really doesn't work and we have to resort to an algorithm, for example in the slice semantics. Let's see how the postcondition works out in a PR... |
Oh and I would say that describing the |
The semantics (as of 2022-08-06) for the descendant selector involving a list:
Which descendants are selected
It is currently implicit that the list selector should select descendants based on the list semantics. This should be made explicit.
Ordering vs implementation consensus
An example from the JSONPath comparison project applies the path
$..['c', 'd']
to the value:The spec states:
Because of the ordering of the array, in all array-sequenced preorders of the above value,
"cc1"
,"dd1"
, and"ee1"
appear before"cc2"
and"dd2"
which appear before"cc3"
which appears before"dd4"
which appears before"cc5"
. So the order of the result according to the spec is:However, the current consensus according to the comparison project is:
where it seems the value is traversed once per item of the list (
['c', 'd']
).Ordering of duplicate nodes
Consider the path
$..[0, 1, 0]
applied to the value:There is just one array-sequenced preorder of this value:
[[1, 2], 1, 2]
(noting the clarification below). But the current list semantics produces duplicates and can reorder the elements of an array, so the resultant nodelist would be:which is not a sub-sequence of
[[1, 2], 1, 2]
.Clarification of array-sequenced preorder
We should make it clear that an array-sequenced preorder is of nodes rather than values.
For example, consider the path
$..[0]
applied to the value:The array-sequenced preorder of this value is
[1, [2], 2, 1]
and the values selected by$..[0]
are1
and2
, but the nodelist[2, 1]
is not a valid result even though it is a subsequence of the values in the array-sequenced preorder. The result is[1, 2]
which is a subsequence of the nodes in the array-sequenced preorder. (In fact, using an array of values to describe an array-sequenced preorder is misleading because it ignores the nodes' locations within the argument value.)The text was updated successfully, but these errors were encountered: