json-path-comparison icon indicating copy to clipboard operation
json-path-comparison copied to clipboard

Allow leading zeroes in numeric literals in Proposal A

Open glyn opened this issue 5 years ago • 12 comments

Looking at https://cburgmer.github.io/json-path-comparison/results/filter_expression_with_equals_number_with_leading_zeros.html makes me wonder if the rational for not supporting this in Proposal A was to allow for octal notation to be added in future.

It would be good either to allow leading zeroes or document the rationale for not supporting this.

glyn avatar Jun 08 '20 10:06 glyn

Here's the second example: https://cburgmer.github.io/json-path-comparison/results/array_slice_with_step_and_leading_zeros.html You can see for one there's a consensus, for the other currently not.

That was I think the only motivation to currently not support it. I'll document that. As always, happy to discuss :)

cburgmer avatar Jun 08 '20 16:06 cburgmer

I think that classic octal notation with leading zero is highly confusing for many modern users. I think that there's no reason to forbid leading zeros. My implementation fails to parse them right now, but I tend to consider it a bug.

But maybe it's wise to forbid leading zeros explicitly.

remorhaz avatar Jun 08 '20 18:06 remorhaz

Strongly disagree, I think leading zeros should be an error, particularly as they are in JSON proper. There is no benefit to allowing them, they add nothing, except confusion whether this represents octal notation or not.

danielaparker avatar Jun 10 '20 13:06 danielaparker

@danielaparker Great point about leading zeroes not being valid in JSON. Case closed?

glyn avatar Jun 10 '20 13:06 glyn

If we say we don't support leading zeros for Proposal A, then we would have our first case where we advocate for not supporting something while the consensus offers a result.

cburgmer avatar Jun 14 '20 19:06 cburgmer

You could always use your prerogative as owner of this site to say a resounding no! to the consensus on this:-) My own view is that the representation of numbers shouldn't differ from ECMA-404. Moreover, most of the JSONPath implementations lack a formal grammar, so it can be hard to tell whether a "feature" has been intended or merely reflects absent validation. For instance I doubt whether any implementation intended to support octal notation for array indexing, as some have. More likely the unintended consequence of using a general purpose to_integer function.

danielaparker avatar Jun 14 '20 20:06 danielaparker

most of the JSONPath implementations lack a formal grammar, so it can be hard to tell whether a "feature" has been intended or merely reflects absent validation

I tend to share this point of view.

I'd like to mention that some implementations allow using JSON object literals. Now let's remember that JSON scalars are also valid JSON documents; so maybe it would be convenient just to delegate JsonPath scalars to JSON spec? I mean, we can just use strict JSON syntax subset for defining JsonPath literals, including:

  • strings/integers in bracket notation;
  • integers in array slices;
  • any valid JSON document as literal in filters.

remorhaz avatar Jun 15 '20 11:06 remorhaz

@remorhaz Agree that wherever possible a formalization of JSONPath should refer to existing specifications.

danielaparker avatar Jun 15 '20 18:06 danielaparker

Now let's remember that JSON scalars are also valid JSON documents; so maybe it would be convenient just to delegate JsonPath scalars to JSON spec?

Just to call out a limitation to that suggestion: we would have to separately support strings with single quotes. Some implementations even support arrays of strings with single quotes.

cburgmer avatar Jun 15 '20 19:06 cburgmer

Dark ages of JsonPath have ruined my beautiful idea, alas. But I still think that we should keep as close to existing JSON spec as possible; something like STRING_KEY ::= JSON_STRING | SINGLE_QUOTED_STRING. And this derives another problem - of extending JSON values, like this: $.foo[?(@.bar=={"a":'b'})]. I mean, the question is: if we allow single-quoted strings in bracket-child, should we forbid them elsewere?

remorhaz avatar Jun 16 '20 10:06 remorhaz

But I still think that we should keep as close to existing JSON spec as possible; something like STRING_KEY ::= JSON_STRING | SINGLE_QUOTED_STRING.

Agreed.

And this derives another problem - of extending JSON values, like this: $.foo[?(@.bar=={"a":'b'})]. I mean, the question is: if we allow single-quoted strings in bracket-child, should we forbid them elsewhere?

I think so, since implementations will want to use an existing JSON parser for parsing JSON values.

danielaparker avatar Jun 16 '20 11:06 danielaparker

The JSON spec for numbers disallows leading zeroes. I'm tending towards making leading zeroes a syntax error. (This will also allow implementations to add octal support as a strict extension of Proposal A if they choose to.)

glyn avatar Jul 13 '20 10:07 glyn