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

From: Davide Bettio <[email-masked]>
Date: Thu, 4 Mar 2021 17:20:23 +0100

Hello,

I've been away from this mailing list for a while, therefore I
apologize if a similar topic has been already discussed.

I have the following use case and I'd like to understand how it can be
addressed from the future JSONPath specification.
I also apologize if this sounds a bit OT here, but I hope that the
purpose of my point will be clearer at the end of this mail.

I'm implementing a logic-less JSON templating system which makes use
of JSONPath, so let's start with an example:

Let's suppose I need to produce an array of objects such as
```
[
  {
     "a": 1,
     "b": "test"
  },
  {
     "a": 2,
     "b": "test"
  }
]
```

by using somekind of for-each construct on an input object such as:

```
{
   "b_value": "test",
   "a_values": [{"foo": 1}, {"foo": 2}]
}
`

therefore the template needs to access both the current item and the
root item by using JSONPath expressions.
At the moment I think there is a grey area about expressions which
don't start with `$`, so I wonder if the following pseudo-template
makes any sense:

```
[...]
{
   "a": "{{ foo }}",
   "b": "{{ $.b_value }}"
}
[...]
```

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, e.g.:

{
   "a": "{{ @.foo }}",
   "b": "{{ $.b_value }}"
}

So I think that the following 2 points need to be addressed:
1. Do we want to allow any kind of reference to any current
context/current item with a standard (or prefered) approach (such as
the mentioned relative JSONPath)?
2. Do we want to use paths without starting '$' or the '@' for this
kind of purpose?

My opinion here is that introducing a semantic difference between
`$.something` and `something` makes sense, and it wouldn't break any
existing semantic since in most of the cases current context == root
context. Moreover that would justify accepting paths as `foo.bar`
(without `$`) for a deeper reason than the mere compatibility with
existing implementations.

I'm looking forward to your opinions.

Regards,
Davide Bettio.

---

From: Carsten Bormann <[email-masked]>
Date: Thu, 4 Mar 2021 18:57:15 +0100

On 2021-03-04, at 17:20, Davide Bettio <[email-masked]> wrote:
> 
> produce an array of objects such as

Well, JSONpath is a bit like XPath, and a lot less like XSLT.
(Although the latter certainly would be nice to have.)

Grüße, Carsten

---

From: Davide Bettio <[email-masked]>
Date: Fri, 5 Mar 2021 10:58:57 +0100

Hello,

> Well, JSONpath is a bit like XPath, and a lot less like XSLT.

I'm aware of this and I also agree, however I still need to understand
if we may support any kind of semantic for accessing any current
item/current context rather than the root item (which is identified by
$), which are the points 1 and 2 of my previous mail.

> 2. Do we want to use paths without starting '$' or the '@' for this

Clearly I don't need to discuss any templating language at the moment
here, but I brought it as a practical example which is useful to
explain why I need to understand if we are going to support relative
JSON Paths.

Furthermore I'd like to understand what kind of opinion people have on
paths that are not starting with $.

Regards,
Davide Bettio.

---

From: Glyn Normington <[email-masked]>
Date: Fri, 5 Mar 2021 19:15:07 +0000

In filter expressions, I think paths should start with @ or $. If we allow
one of these to be elided, then the user has to remember which one can be
elided.

I'm sympathetic to optionally omitting the initial $ of a JSONPath
expression because this is unambiguous, but I would be happy with $ being
mandatory since this is consistent with the above rule for filter
expressions.

On Fri, 5 Mar 2021, 09:59 Davide Bettio, <[email-masked]> wrote:

> --
> Jsonpath mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/jsonpath
>

---

From: Greg Dennis <[email-masked]>
Date: Fri, 5 Mar 2021 21:41:27 +0000 (UTC)

Glyn and I are in agreement in this. (Sound the trumpets)

  On Sat, 6 Mar 2021 at 8:15 am, Glyn Normington<[email-masked]> wrote:   -- 
Jsonpath mailing list
[email-masked]
https://www.ietf.org/mailman/listinfo/jsonpath

---

From: Davide Bettio <[email-masked]>
Date: Tue, 9 Mar 2021 16:25:51 +0100

Hello,

I opened an issue on this topic:
https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-jsonpath/issues/59

To be honest I am still of the opinion that omitting $ is the right
approach for relative JSONPaths, which is a similar approach to XPath
relative paths (which they don't start with /).

Anyway the most important thing for me is to reach a consensus on the
idea of supporting relative paths (to the current context) with some
kind of syntax.

Regards,
Davide Bettio.

Il giorno ven 5 mar 2021 alle ore 20:15 Glyn Normington
<[email-masked]> ha scritto:
>
> In filter expressions, I think paths should start with @ or $. If we allow one of these to be elided, then the user has to remember which one can be elided.
>
> I'm sympathetic to optionally omitting the initial $ of a JSONPath expression because this is unambiguous, but I would be happy with $ being mandatory since this is consistent with the above rule for filter expressions.
>

---

From: Davide Bettio <[email-masked]>
Date: Sat, 13 Mar 2021 12:57:43 +0100

Hello,

Greg Dennis made a really good synthesis on this topic:
https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-jsonpath/issues/59#issuecomment-797212814

Please, take a look at it and let me know what you think.

Regards,
Davide Bettio.