3 ms·
How can I use wildcards in queries? For example consider this. echo '{"users":[{"name":"s1","id":1},{"name":"s2","id":2}]}'|jid I can query users[0].id
by asimjalis 10y ago
How can I use wildcards in queries?
For example consider this.
echo '{"users":[{"name":"s1","id":1},{"name":"s2","id":2}]}'|jid
I can query users[0].id or users[1].id. How can I get all the ids? I tried users[*].id which didn’t work.
In Clojure I use specter [1] for this which is able to handle wildcards using ALL.
[1] https://github.com/nathanmarz/specter https://github.com/nathanmarz/specter
- bbrks 10y agojq uses empty square brackets as a way of accessing all of an arrays elements. Not sure if this tool uses the same syntax? E.g. users[].id
- gwu78 10y agoecho '{"users":[{"name":"s1","id":1},{"name":"s2","id":2}]}' |exec tr '{' '\12'|exec sed '/name/!d;s/\"//g;s/}.*//' output: name:s1,id:1 name:s2,id:2