-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
Description
I was surprised to find out that you cannot chain multiple and
/ or
conditions after each other?
For example, this results in a syntax error:
// Input:
[
{"name": "Chris", "age": 23, "city": "New York"},
{"name": "Emily", "age": 19, "city": "Atlanta"},
{"name": "Joe", "age": 32, "city": "New York"},
{"name": "Kevin", "age": 19, "city": "Atlanta"},
{"name": "Michelle", "age": 27, "city": "Los Angeles"},
{"name": "Robert", "age": 45, "city": "Manhattan"},
{"name": "Sarah", "age": 31, "city": "New York"}
]
// Failing queries:
filter((.city == "New York") and (.age > 30) and (.name == "Sarah"))
filter((.city == "New York") or (.age > 30) or (.name == "Sarah"))
// Result:
SyntaxError: Character ',' expected (pos: 45)
The only way I found around this was to nest the conditions resulting in ugly queries:
filter(
or (
(.city == "New York") or (.age > 30),
(.name == "Sarah")
)
)
Or for a more verbose example:
filter(
or (
(.city == "New York"),
or (
(.name == "Sarah"),
or (
(.name == "Emily"),
or (
(.name == "Kevin"),
or (
(.name == "Michelle")
)
)
)
)
)
)
Surely this isn't how people are expected to use the library? So I think if the or
and and
functions could support multiple parameters, it would be a lot simpler.
Suggested Changes:
// Should be valid:
(.name == "Sarah") or (.name == "Emily") or (.name == "Kevin")
// Should also be valid:
or (
(.name == "Sarah"),
(.name == "Emily"),
(.name == "Kevin")
)