-
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
JSONPath expression and bracket-notation #57
Comments
@goessner wrote
There is no need to guess, the answer is in Christoph Burgmer's comparisons. The answer is "forgiving". Daniel |
@goessner wrote
The only example of a
and I believe it was Glyn that noted it can be rewritten without using expressions. My sense is that this construct wouldn't be missed. But expressions are also used within filters. Whether 3 or 4, I don't have a good enough understanding of the use cases for applying a filter to objects. When applied to an array, it is reasonable to expect a certain amount of homogeneity in the elements, so it makes sense to apply common criteria to them. But that isn't generally the case for object values. And when we select object values, we lose the association with their keys, which makes the results less helpful. But I'd be interested in hearing about use cases. Daniel |
In issue #17 I highlight There is a lot of overlap between these two issues. Maybe we should consider consolidating them. |
Personally, I like having both forms:
|
@gregsdennis wrote
Given that both were in the original article, and if filters with expressions are implemented, there is little extra implementation effort, it seems reasonable.
More generally, If the current node If the current node
More generally, Typical conditions to determine whether an arbitrary JSON value can be considered
For comparison, JMESPath requires all of these conditions except zero integer, in JMESPath, an expression that evaluates to zero is not regarded as A similar requirement, to find the effective boolean value of a (more complicated!) value, is present in XPath, and is described here.
Are you thinking about something like
or perhaps
or
?
Perhaps. Although something like (The rationale for the name |
@danielaparker yes, I think you restated what I said. I'm not so worried about writing "spec-y" language in an issue, though, so much as the concept. If we can state it in plain language and get people to agree on the idea, we can develop a more precise language to describe it later.
I had a heck of a time implementing "falsiness" and other loose equality things in .Net when I was building my JsonLogic library. In a strongly-typed language/framework (where I spend most of my time), this idea is counterintuitive and just feels wrong. But I understand the roots. If we proceed with this kind of thing, then I suggest we approach it as I describe in #15 where I propose a DSL (I also give reasons there, so I won't repeat them here).
I like this, but (and?) it opens the door for other functions (possibly an extension point). Perhaps things like array/object length for the Also related (and probably another candidate for consolidation): #47. It sounds like we like the idea of supporting it. |
Interesting discussion that is pretty much implemented in the document now. |
I was thinking a while about
[(...)]
expressions (we may need another term here: 'evaluatable' or something) and filter expressions[?(...)]
(or simply 'filters'?).In order to discuss bracket-notation inside of JSONPath expressions – leaving out unions for now, we can address implicitly either JSON objects by using a string indicating a member name ...
or JSON arrays by using an integer as array index.
I'm not sure, how strict or forgiving implementations handle
$..['42']
here ... I assume the latter.$..[(#)]
Now, when applying
$..[(#)]
, then abstract'#'
should evaluate to a string in case of (1) and to an integer in case of (2), if it wants to have a chance to select anything.Now consider the root selector
'$'
being part of the evaluatable in question ...and ...
JSON documents containing such a level of indirection may be treated well by JSONPath this way. It's hard for me to imagine other use cases, since both expression must resolve to string and integer, in order to make sense.
This time consider the current element/node indicator
'@'
being used ...and ...
Again both expression must resolve to string and integer respectively. So current item
'@'
needs to reference its container, i.e. object'o'
and array'a'
in the examples above. The benefit is significantly less here in contrast to the use of the root selector'$'
. Again we can perform some kind of 'pointing' from one location to another in a single JSON document. But this time an object member is addressed more restrictively from its direct descendant or from its sibling or thats descendant.My former example
$..book[(@.length-1)]
addresses via'@'
the arraybook
and implies that it has a member with name
length
. This is true for JavaScript, but does not apply generally and thus makes it a bad example.Daniel largely agrees with the uselessness of this case in his post "@ and the current element" on the list https://mailarchive.ietf.org/arch/browse/jsonpath/, but he and others may have some other practical uses in mind ... ?
$..[#]
Daniel is pointing to another variant of expression evaluating
$..[@.address.city]
on stackoverflow. Basicallythat use is questionable, as there exists another more intuitive JSONPath query delivering the same result, as shown in the example. Interesting is the idea, that the expression inside the brackets is evaluated, as if it were outside. Current item
'@'
here references its container as in$..[(#)]
expressions above. A benefit (?) of that might come in combination with unions, which we won't discuss here (but possibly in another later issue).$..[?(#)]
JSONPath filters seem to be of most practical use. It allows to perform tests while iterating over a JSON container (object or array). If the boolean test results in
true
, the object member or array element is selected, thus filtering data items out. In tests the symbols'$'
and'@'
may be used, meaning the root node and current node (is node a valid term in the draft?), as in ...It's important to note, that symbol
'@'
herein does not reference the JSON container as before with[(...)]
expressions, but the members or elements contained, while iterating.Interestingly there is good agreement with arrays, but obviously confusion regarding objects among the implementations. See enlightening issue #47 for discussion.
Conclusion
Workgroup members seem to be very reluctant regarding those evaluatable expressions (see Glyn's comment). One reason might be security considerations #25. I find Greg's comment remarkable, where he proposes two of the following options:
I think, whatever option we will choose – my favorite would be 2. possibly combined with 4. and/or 5. – there should be a clear definition, how
'@'
symbol is to be interpreted, when used by implementations. I'm not sure, if this requires an explicit grammar and if so, how detailed it has to be then.I'm also not sure, if it's possible, to announce addition of those stuff to later versions of the draft (like TC39 handles proposals).
The text was updated successfully, but these errors were encountered: