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 comparison is broken #19

Open
Greven145 opened this issue May 17, 2019 · 2 comments
Open

Numeric comparison is broken #19

Greven145 opened this issue May 17, 2019 · 2 comments

Comments

@Greven145
Copy link

When comparing numeric values, I get an error:

(feature/1176)$ echo '[{"vote": 10, "Name": "First"},{"vote": 5, "Name": "Second"}]' | jp "[?vote!='10'].{Name: Name}"
[
  {
    "Name": "First"
  },
  {
    "Name": "Second"
  }
]
(feature/1176)$ echo '[{"vote": 10, "Name": "First"},{"vote": 5, "Name": "Second"}]' | jp "[?vote==10].{Name: Name}"
SyntaxError: Invalid token: tNumber
[?vote==10].{Name: Name}

Using v 0.1.3

@rarylson
Copy link

rarylson commented Mar 21, 2020

I think you're using a wrong syntax.

In the first line, when you write '10', you are talking about the string "10", not the number 10.

In the second line, when you write 10, without ` or ', this is a wrong syntax.

Try this:

$ echo '[{"vote": 10, "Name": "First"},{"vote": 5, "Name": "Second"}]' | jp '[?vote!=`10`].{Name: Name}'
[
  {
    "Name": "Second"
  }
]

$ echo '[{"vote": 10, "Name": "First"},{"vote": 5, "Name": "Second"}]' | jp '[?vote==`10`].{Name: Name}'
[
  {
    "Name": "First"
  }
]

@jawad-aziz-farhad
Copy link

Double quotes with numeric values throws error. You need to wrap your query in single quotes and numeric value in back ticks.

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

3 participants