jp
jp copied to clipboard
Numeric comparison is broken
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
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"
}
]
Double quotes with numeric values throws error. You need to wrap your query in single quotes and numeric value in back ticks.