Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.[] doesn't work as expected #36

Open
pkoppstein opened this issue Jan 29, 2023 · 2 comments
Open

.[] doesn't work as expected #36

pkoppstein opened this issue Jan 29, 2023 · 2 comments

Comments

@pkoppstein
Copy link

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?

@davesnx
Copy link
Owner

davesnx commented Jan 29, 2023

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 davesnx changed the title misleading documentation regarding .[] .[] doesn't work as expected Jan 29, 2023
@pkoppstein
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants