Skip to content

Read properties from JSON files using the shell. 🏯

License

Notifications You must be signed in to change notification settings

ORESoftware/read.json

Repository files navigation


Version

@oresoftware/read.json

A simple alternative to jq for bash/shell Reads in JSON to stdin, and always writes JSON to stdout

installation

npm i -g @oresoftware/read.json

Usage

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"}}}