A simple alternative to jq for bash/shell Reads in JSON to stdin, and always writes JSON to stdout
npm i -g @oresoftware/read.json
Given a foo.json file like so:
{
"foo":{
"bar": {
"baz":"biz"
}
}
}
You can get 'biz' by running:
$ read_json -k 'foo.bar.baz' < foo.json
or equally like so:
$ read_json -k 'foo.bar.baz' -f foo.json
To pass an expression to evaluate, use:
$ read_json --eval "['foo']['bar']['baz']" -f foo.json
note that if you have keys with dots in them, it's necessary to use the --eval
technique:
$ read_json --eval "['foo.x.y']" -f foo.json
As a final example, if you run this:
$ cat foo.json | read_json
You will get this:
{"foo":{"bar":{"baz":"biz"}}}