jp icon indicating copy to clipboard operation
jp copied to clipboard

Numeric comparison is broken

Open Greven145 opened this issue 6 years ago • 2 comments

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

Greven145 avatar May 17 '19 19:05 Greven145

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"
  }
]

rarylson avatar Mar 21 '20 22:03 rarylson

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

jawad-aziz-farhad avatar Sep 30 '21 21:09 jawad-aziz-farhad