Are nested objects supported in a lens selector? #224
-
Hi, I may be missing something obvious, but I can't figure out if the lens selector can filter against nested objects or not. Here's an example input json: [
{
"metadata": {
"unique_id": "fizzbuzz"
},
"data": ["foo", "bar", "baz"]
},
{
"metadata": {
"unique_id": "giant"
},
"data": ["fee", "fi", "fo", "fum"]
}
] What I'd like to do is get the So if I'm looking for [
[
"foo",
"bar",
"baz"
]
] Intuitively, I thought the lens selector would be able to do something like this, but in practice it gives a parse error: jql '|={"metadata""unique_id"="fizzbuzz"}' example.json # Unable to parse input The only thing I was able to figure out was a workaround with flattening. While this does give the desired output, flattening is destructive and I'd rather avoid it if possible. jql '|> .. <| |={"metadata.unique_id"="fizzbuzz"} |> "data" <|' example.json # desired output |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @zkxs, Thanks for your feedback! Indeed this is not possible in the current state of jql/crates/jql-parser/src/tokens.rs Line 75 in dbf8997 jql/crates/jql-parser/src/tokens.rs Lines 109 to 118 in dbf8997 To make it work, I'll need to refactor the parser implementation to allow a I'll think about it and see if that's not going to add too much complexity. |
Beta Was this translation helpful? Give feedback.
-
@zkxs I've prepared a draft PR to allow a subset of selectors to work with lenses. I need to do some more testing (and update the documentation too) and then will make a new release. |
Beta Was this translation helpful? Give feedback.
-
@zkxs I've just released a new major version which now supports lenses with selectors. Thanks a lot for bringing this issue to the table 👍🏼 . |
Beta Was this translation helpful? Give feedback.
Hi @zkxs,
Thanks for your feedback!
Indeed this is not possible in the current state of
jql
since aLens
is basically a tuple of key (str
) +LensValue
(a JSON primitive):jql/crates/jql-parser/src/tokens.rs
Line 75 in dbf8997
jql/crates/jql-parser/src/tokens.rs
Lines 109 to 118 in dbf8997
To make it work, I'll need to refactor the parser imp…