-
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
Filter Expressions #64
Comments
This actually already has an issue: #47. |
Can we close this? |
Filter expressions Implementations agree, that filter expressions are an essential feature with JSONPath. They are considered much more important than "index expressions" There are already some discussions about filters (historically ascending):
1. Term "filter expression"The WG still has to decide, if we want to use the term "filter expression" in the draft, as there are some objections against it (#20). As an alternative the term "filter selector" was proposed, which is used below. 2. Apply Filter Selector to ObjectsThere seems to be no agreement, if filters should be applied to objects (#47). Consider a school, {
"students": [...],
"staff": [...],
"teachers": [...]
} while looking for the array(s) containing persons named 'Müller' by I can see value for allowing filter selectors applied to objects and not really a rational reason to exclude them from filtering. 3. How Filter Selectors WorkFilter selectors work via iterating over arrays and objects, provided the latter is allowed by the spec. 3.1 SelectingDuring iteration process the value of each array element or object member is taken and evaluated against an implicite boolean expression 3.2 The Current Value
|
First, why post here? This is a duplicate issue, as I noted.
A being "more important" (really meaning "more commonly used") than B does not imply that B should be excluded. The index expression format has its uses that cannot be replicated with other mechanisms. It should be included. |
We still need to define "truthiness." There is still active discussion on this topic.
I see the utility of this. It does open up the door for other operators. The inverse of this operator would be I'm sure we can think of others.
We need to address scoping. Maybe |
Correctum: 4.5 Nested Filter SelectorsAs I should have been thinking a little longer, I finally realized, that there is no need for nested filter selectors in example above ... $.arr[?(@.type == 'a' && @.subarr[?(@.prop == 'b')])] ... as this might be resolved conventionally by $.arr[?(@.type == 'a' && @.subarr[*].prop == 'b')])] without nesting. I am doubtful, that significant real world examples exist, which are not resolvable without nesting. |
Can be solved without We should take care, not inflationary inventing operators. |
yes, you are right. Or better define falsiness, as Daniel proposes ...
adding ...
|
What are we saying here?
My point is that I don't like the idea of loose equality at all, and I expect implementors in other strongly typed language will have the same reservations. |
Hmm ... what have I been thinking? You are right. It doesn't work that way, of course. I did not intend to introduce an implicit 'contains' operator. Given this, nested filters and/or a contains operator is still worth a discussion. |
We don't address implementors but ordinary users of JSONPath, which are not necessarily programmers using strongly typed languages. Ok ... what exactly do equality comparisons look like then? What do you propose? |
I think the spec should define whether or not any given JSONPath is syntactically valid rather than leaving this up to implementations. What do others think about this general principle? Also, I'm not sure how the spec's syntax and compliance test suite could allow implementation-specific variants. There isn't much of a consensus among existing implementations about the behaviour of nested filter expressions. However, Proposal A neatly disallows nested filter expressions, along with certain other complicated filter expressions. OTOH, I quite like not having apparently arbitrary syntactic restrictions and so my implementation allows nested filter expressions. |
Doing loose equality in a strongly-typed system is a serious pain. However, strict equality in a loosely-typed system is generally easy. For example, JS uses the
Definitely, yes, the spec should be as precise and prescriptive as possible on what it covers. However, I do think that it does need to allow for implementations to expand on the domain in order to foster new syntaxes and ideas, so long as those implementations call out those deviations as non-standard. I think the spec should define its support for nested queries, even if it's to say they're not supported. I also think that it should support index queries. However, I recognize that it says nothing at all in regard to expressions currently, and I'm on board with getting something in place to cover the things we at least agree on right now so long as it's done in a way to leave the door open to incorporate these other features after we've discussed them further. |
The spec should be well-defined, but also provide extension points -- both for third parties to use and for evolution of the spec itself. |
Allowing non-scalar comparisons in filter expressions leads to some weirdness. For example, the Background: vmware-labs/yaml-jsonpath#31 The JSONPath comparison project has a couple of relevant examples:
I would prefer the spec to disallow non-scalar comparisons. Christoph Burgmer found a neat way to disallow this in the grammar of Proposal A. |
Found a StackOverflow question where the OP is looking to use a unary
|
.. interesting, why he refuses to use `x!=y` instead. We do need logical
not-operator `!` not only for completeness, but also as an explicit
complementary for implicit existence test (undefined).
Am 24.06.2021 um 23:49 schrieb Greg Dennis:
…
Found a SO question <https://stackoverflow.com/q/68020301/878701>
where the OP is looking to use a unary |!| to negate a user-supplied
expression.
|$[?(!(<expr>))] |
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#64 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFM6WSQPEG5YQJPHDREVMLTUOR5XANCNFSM4Y6GZMWA>.
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
Virenfrei. www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
|
If you look at the rest of the post, he shares his code where you can see that he's literally just interpolating user input into the expression and using the negation operator to invert the filter. This is why he says the |
We received an SO question that works be helped by the The asker wants a path that can identity paths to arrays that contain two values. Such a query could be
returning paths instead of values (so they can get the keys). This iterates over the values in the top-level object (which are themselves arrays) and uses the |
Here's another SO question that would benefit from nested expressions. |
This discussion led to useful changes to the draft but does not seem to have actionable items left. |
I tried to understand the final consensus on this [{"target": ["a", "b"]}, {"target" : ["c", "d"]}] In my understanding in some implementations I can do: $[? @.target == "a" ] but that seems to be ruled out cause it is actually operator overloading. Or $[? "a" in @.target ] But it is not a valid query for the current grammar. |
I believe the current consensus is that the only paths allowed inside filter expressions are singular paths, and that rules out nested filters. |
Ok, thank you for your answer! But then a singular path can still resolve in a node that is an array, right? Is there any plan to add particular operators to deal with array items? like the |
Correct.
No, we decided against including the
Perhaps. |
Searching for an element in an array is a common use case, and is readily achieved in both of the foundational JSONPath implementations, Goessner Javascript JSONPath and Jayway Java JSONPath. Given
In Goessner:
In Jayway:
Both produce:
Note also that this capability is supported in the modern competitors to JSONPath, in JMESPath, with the contains function, and in JSONAtat, with the in operator. Perhaps the committee would reconsider?
If some entity were to register a "contains" function as an extension point, presumably users of that entity's implementation would have this capability. But there wouldn't be interoperability, which would presumably be the goal of the standardization exercise. Daniel |
This is because Goessner uses the underlying language to process expressions, which is something that we explicitly forbid in favor of interoperability. |
Once the syntax of the extensions point is settled, I think that the group can define a "core set" of extension points that have to be supported in all compliant implementations. This should help interoperability at least for the common use cases. |
Yes, but from the user's point of view, it's cold comfort if a capability that they had with another version of JSONPath isn't available in the committee's interpretation of JSONPath. One of the appeals of JSONPath Javascript/Python has always been that the user could write expressions with all the capabilities of Javascript/Python available. The Jayway implementation, which I believe was the first quality implementation to define it's own expression language, introduced operators and functions for some of the most common requirements, including searching for an element in an array. And JSONPath's modern competitors have all introduced a rich set of operators and/or functions to satisfy common search use cases. Best regards, |
My point, though, is that it needs to be defined in the spec. That's not to say it shouldn't or won't be, but that's a lot of work and not the target for the spec right now. |
Indeed :-) |
(This was original raised in #54 and now being split out)
I tend to let implementations and their "normative force of the factual" decide here or in doubt agree to Glyn's restriction to arrays.
I am very unhappy with confusing
$..book[(@.length-1)]
, where'@'
addresses the array itself and implies that array has alength
property. In filter expression examples'@'
more consistently addresses the current array element.The invocation of 'the underlying scripting engine' wasn't meant a serious normative aspect, but rather a quick and dirty solution for JavaScript and PHP implementations at that time.
Corner Case
Hmm ... this seems to be a hint to better exclude
'-'
from dot-child-selector syntax. I think I have read more discussion about that, currently don't know where.The text was updated successfully, but these errors were encountered: