2 ms·
Shameless plug but I've also written a language (murex) for shell scripting which can be used for this too: open test.json -> [ countries ] open test.j
by hnlmorg 7y ago
Shameless plug but I've also written a language (murex) for shell scripting which can be used for this too:
open test.json -> [ countries ]
open test.json -> [[ /countries/0 ]]
open test.json -> [ countries ] -> [ 0 2 ]
Single brackets only return the next level deep but can retrieve multiple items (and negative integers to count from the end of an array). Double brackets are to specify a path. So [[/foo/bar]] is literally the same as [foo]->[bar]
Lastly the 4th example:
open test.json -> [ countries ] -> foreach c { echo $c[name] }
Unfortunately this one doesn't output it in JSON. If you needed that you could chain another command to reformat it:
open test.json -> [ countries ] -> foreach c { echo $c[name] } -> cast str -> format json
This works because murex can auto-convert between lists, JSON, YAML, CSV and a few other structured formats. However it's fair to say it is a lot more verbose than jsonnet and jql in that last example.
Github repo: https://github.com/lmorg/murex https://github.com/lmorg/murex
I've been using this as my primary shell for a few years now and, like yourself, I've never bothered to learn jq because of that.
NB all of the above example are running from inside the murex interactive command line (like bash). If you wanted to run it like jq/jql then you'd need to do the same sort of thing as bash:
murex -c 'open test.json -> [ countries ]'