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

Numeric literals can only wrapped with backticks, not single quotes #85

Open
slandelle opened this issue Jul 31, 2022 · 1 comment
Open

Comments

@slandelle
Copy link

Hi,

According to the JMESPath specification:

literal           = "`" json-value "`"

This implementation doesn't abide to the specification and allows literals to be also wrapped with single quotes.

{
"status":"GOOD",
"fruits":[
  {
    "name":"Apple",
    "details": {
       "size":500
      }
  },
  {
    "name":"Cherry",
    "details": {
        "size":100
      }
  }]
}
fruits[?details.size >= `500`]
fruits[?details.size >= '500']

On the online evaluator on https://jmespath.org/ (using this implementation), both following expressions work.
Only the former should. The latter should return an empty array.

For the record, the Java implementation works as expected.

Regards

@springcomp
Copy link

springcomp commented Aug 1, 2022

JMESPath used to support strings using this syntax: `this was a string`.
However, JEP-12 made this syntax obsolete.

Now, the grammar is much clearer. You can only have:

  • quoted-string : simple JSON strings easy to input using simple quotes. e.g 'hello world!'.
  • raw-string literals : JSON values typed verbatim (except, backtick must be escaped). e.g `"{}`" would be an empty JSON object. Please, note that a JSON string has surrounding double quotes, and thus mus be input like so `"this is a string"`.

Your question is raised in the context of numeric literals. JMESPath does not support JSON numbers in its grammar. So those must be input using raw-string literals. Thus:

  • fruits[? details.size >= `500` ] filters all fruits whose size is greater than number 500.
  • fruits[? details.size >= '500' ] filters all fruits whose size is greater than string "500". Probably not what you want.

Comparisons between numbers and strings is currently undefined in the grammar as ordering operators are only valid between two numbers. However, popular implementations do make some attempt to cast the string to a number before performing the comparison, so it mostly works even though it is not standards-compliant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants