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
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 ]'I haven't used it yet, but the syntax seems simpler than some.
I never before wanted to write object oriented JSON, but now my mind has been opened.
For those who haven't yet seen it/opened the link, it's 20% project that describes itself as:
> A data templating language for app and tool developers
- Generate config data
- Side-effect free
- Organize, simplify, unify
- Manage sprawling config
> A simple extension of JSON
- Open source (Apache 2.0)
- Familiar syntax
- Reformatter, linter, editor & IDE integrations
- Formally specified
For an Open Source project of mine (https://github.com/buildbarn, a remote build cluster implementation for the Bazel build system), we are using go-jsonnet as the config file parser library. This means that people can use JSON, but if they need something that’s more flexible, they can add Jsonnet statements immediately. It’s also possible to have that as a preprocessing stage (init scripts), but in a containerized world it’s easier to have it embedded.
One of the nice things about doing that is that I also don’t need to write code to load TLS certificate data from disk. People can either embed their secrets directly into the config file, or they can use Jsonnet’s ‘importstr’ keyword to load separate PEM files from disk.
Somewhat related to that: Jsonnet also allows people to write libraries for constructing more complex JSON files. For example, the Grafana folks have released a library (https://github.com/grafana/grafonnet-lib) that allows you to easily build Grafana dashboards from code.
That sounds awesome. I'd expect it's worth it just to have self and $.
And not only that, jsonnet can also produce yaml and ini files. I might try using it to configure my whole machine...
> TODO: This page still needs to be written.
Looks like it is not ready for prime time yet... (Not to mention that it seems to have no support for stdin input, multiple input files, and json lines format - which are my main uses cases for jq)