Subject: Re: [Jsonpath] Absolute ($.foo) and relative JSONPaths semantics

From: Daniel P <[email-masked]>
Date: Fri, 5 Mar 2021 08:02:41 -0500

> From: Davide Bettio <[email-masked]>
>
> Here above I made the assumption that when `$` (the root item) is not
> used the JSONPath is relative to some kind of current context.
>
> Another possibility is using "@" for this kind of purposes,
>
If I understand this post correctly, the only use you would make of
a "$", "@" or "" at the front of a JSONPath expression is as a flag
to determine what JSON instance to pass to a JSONPath select
function. As far as the JSONPath select function is concerned,
"$.foo" and "@.foo" and "foo" would mean exactly the same thing,
the JSONPath select function doesn't know anything about your
"current context", it knows about its current instance, which is the
instance that you've passed as an argument. That being the case,
why wouldn't you simply keep a flag as a separate item in your
template for that purpose?

Daniel

---

From: Daniel P <[email-masked]>
Date: Fri, 5 Mar 2021 10:14:27 -0500

>
> Furthermore I'd like to understand what kind of opinion people have on
> paths that are not starting with $.
>
Should the WG see it that way, I don't think there would be any
difficulty, conceptual or technical, to support paths starting with @,
understood as the current node. At the start of an expression, the
value of the current node _is_ the JSON instance being evaluated by
the JSONPath expression. In the course of the evaluation, the value
the current node represents will change to reflect the node being
evaluated.

But I don't think allowing the root or current node symbol to be
omitted is a good idea. Consider

[{"true" : true}, {"false" : false}]

The expression, $[?(@.true == true)], which has a filter that
evaluates a JSONPath expression relative to the current node @, and
compares it to the JSON literal value true, gives

[{"true" : true}}]

If we allowed the current node symbol @ to be omitted, the expression
would be ambiguous.

For comparison, JMESPath also uses the @ symbol to denote the current
node, but requires that it be omitted except as a bare expression,
being understood.The comparable expression in JMESPath would be

[?(true == `true`)]

but JMESPath delimits JSON literals with "`", so the ambiguity does not arise.

There are some implementations that allow the dot notation without
root (".foo"), see
https://cburgmer.github.io/json-path-comparison/results/dot_notation_without_root.html)
, and more that allow the dot notation without root and dot ("foo"),
see https://cburgmer.github.io/json-path-comparison/results/dot_notation_without_root_and_dot.html.
Personally, I'm not enthusiastic about that. My own view is that path
syntax should follow common conventions, and should not vary depending
on whether they appear in the main path or in expressions.

Daniel Parker