MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

Variables in object binding pattern #50

Closed itchyny closed 2 years ago

itchyny commented 2 years ago

jq allows to bind object value by using variable in object keys.

❯ jq -c '. as {$a:[$b]} | {$a,$b}' <<< '{"a":[1]}'
{"a":[1],"b":1}

❯ xq -c '. as {$a:[$b]} | {$a,$b}' <<< '{"a":[1]}'
Error: compile query

Caused by:
    CompileError(UnknownVariable(Identifier("a")))

❯ xq --version
xq 0.1.9-95558180fabd53143a91d72e226780939461f8c5
MiSawa commented 2 years ago

Thank you for reporting!

So I guess it has to be compiled as same as

$ xq -c '. as {$a,a:[$b]} | {$a,$b}' <<< '{"a":[1]}'
{"b":1,"a":[1]}