Subject: [Jsonpath] Remarks on the JSONPath ABNF grammar in draft-goessner-dispatch-jsonpath-00.html

From: Daniel P <[email-masked]>
Date: Thu, 12 Nov 2020 12:37:09 -0500

In https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html,
in Section 3, there is a suggested JSONPath ABNF grammar.

(1) A slice expression within square brackets  is expressed as

value-expression *2(":" value-expression)

value-expression = *DIGIT / name
                 / script-expression / filter-expression

Note that a slice expression in Goessner is defined with reference to
the (long since abandoned) ECMASCRIPT 4. The original link is lost,
but there is some discussion here,
https://web.archive.org/web/20070125020659/developer.mozilla.org/es4/proposals/slice_syntax.html.

I've never seen an attempted formalization of JSONPath (or JMESPath,
for that matter) that defines a slice expression allowing general
expressions, nor do I think there is any prior experience with that in
any existing implementations. Also note that negative numbers are
allowed in slice expressions as per ECMASCRIPT 4. The usual definition
is

slice-expression  = [number] ":" [number] [ ":" [number] ]
number            = ["-"]1*digit

(2) In

step = ".." name ; nested descendants
     / "." name ; child (dot notation)

name = "'" text "'"
     / "*" ; wildcard

a name is defined as a single quoted string or a wildcard.

But note that JSONPath also supports unquoted strings. So perhaps

step = ".." name-or-wildcard ; nested descendants
     / "." name-or-wildcard ; child (dot notation)

name-or-wildcard = unquoted-name / single-quoted-name / wildcard

single-quoted-name = ; must escape single quotes in character sequence
unquoted-name = ; must start with an alphabetic character

Also note that a number of implementations (but not Goessner) support
double quoted names as an extension.

(3) Many JSONPath implementations support functions. For example the
popular and influential jayway implementation,
https://github.com/json-path/JsonPath, supports a somewhat limited
idea of functions that can be invoked at the tail end of a path - min,
max, avg, stddev, length, sum. We also see this adopted in Oracle's
version of JSONPath,
https://docs.oracle.com/cd/E60058_01/PDF/8.0.8.x/8.0.8.0.0/PMF_HTML/JsonPath_Expressions.htm.
There are other implementations that take a more general approach to
functions, more along the lines of XPath.

Is it within the scope of the working group to discuss functions?
There are some implications for the grammar.

Daniel

---

From: Glyn Normington <[email-masked]>
Date: Fri, 13 Nov 2020 07:30:21 +0000

Hi Daniel

On 12 Nov 2020, at 17:37, Daniel P <[email-masked]> wrote:
> https://web.archive.org/web/20070125020659/developer.mozilla.org/es4/proposals/slice_syntax.html <https://web.archive.org/web/20070125020659/developer.mozilla.org/es4/proposals/slice_syntax.html>.

We plugged that gap in the Gössner article thus:

https://jsonpath-standard.github.io/internet-draft/#name-array-selector-2 <https://jsonpath-standard.github.io/internet-draft/#name-array-selector-2>

which may be a safer starting point for the WG.

Regards,
Glyn