Skip to content
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

Allow leading zeroes in numeric literals in Proposal A #46

Open
glyn opened this issue Jun 8, 2020 · 12 comments
Open

Allow leading zeroes in numeric literals in Proposal A #46

glyn opened this issue Jun 8, 2020 · 12 comments
Labels
Proposal A Anything discussing the advance of the Proposal A for a formal specification of JSONPath

Comments

@glyn
Copy link
Collaborator

glyn commented Jun 8, 2020

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.

@cburgmer
Copy link
Owner

cburgmer commented Jun 8, 2020

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 :)

@remorhaz
Copy link
Collaborator

remorhaz commented Jun 8, 2020

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.

@cburgmer cburgmer added the Proposal A Anything discussing the advance of the Proposal A for a formal specification of JSONPath label Jun 8, 2020
@danielaparker
Copy link
Collaborator

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.

@glyn
Copy link
Collaborator Author

glyn commented Jun 10, 2020

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

@cburgmer
Copy link
Owner

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.

@danielaparker
Copy link
Collaborator

danielaparker commented Jun 14, 2020

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.

@remorhaz
Copy link
Collaborator

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.

@danielaparker
Copy link
Collaborator

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

@cburgmer
Copy link
Owner

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.

@remorhaz
Copy link
Collaborator

remorhaz commented Jun 16, 2020

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?

@danielaparker
Copy link
Collaborator

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.

@glyn
Copy link
Collaborator Author

glyn commented Jul 13, 2020

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal A Anything discussing the advance of the Proposal A for a formal specification of JSONPath
Projects
None yet
Development

No branches or pull requests

4 participants