query-json icon indicating copy to clipboard operation
query-json copied to clipboard

`.[]` doesn't work as expected

Open pkoppstein opened this issue 2 years ago • 2 comments

The README indicates that .[] has been implemented, but the following queries both fail using query-json (version 0.5.20):

$ jq '.[0,1]' <<< [1,2,3]
1
2
$ jq '.[]' <<< [1,2,3]
1
2
3
$ 

p.s. Is this project still alive?

pkoppstein avatar Jan 29 '23 03:01 pkoppstein

Hi @pkoppstein

.[] is equivalent as . | .map so probably doable with a workaround. If .[] isn't working as expected, can you give me an example? If it doesn't work it might be a bug.

Array index access work great:

q '.[1]' --kind=inline '[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]'

Regarding your question about the "liveness" of this project: I'm not entirely sure what's death or alive, works great for my usage and isn't complete. You can use it if you want, you can submit a PR/issues and will get merged/fixed.

davesnx avatar Jan 29 '23 19:01 davesnx

@davesnx - Thanks for your response. The two examples I gave in my initial post show the two queries of interest together with the actual output produced by jq, which is of course in each case also the correct/expected output.

Regarding .map:

query-json '.map' <<< [1,2,3]

produces: [1, 2, 3]

which has nothing to do with the expected output from .[].

Please also note that your response does not address the second issue regarding .[E] when E is a stream.

pkoppstein avatar Jan 29 '23 21:01 pkoppstein