G. Deward G. Deward - 1 year ago 68
JSON Question

How to retrieve JSON value in BASH (automatic version in git commit)?

How can I retrieve the

attribute from the following json file AND use it in a BASH script?..

file package.json

"name": "myapp",
"version": "0.0.1"

desired script: bpush.sh

gulp bump
git add -A
eval $pkg_ver = getjson('./package.json', 'version')
git commit -a -m "$pkg_ver"
git push origin master

Obviously, the
function is invalid.
That is what I'm trying to figure out.

Answer Source

If your json file is more complex then I would suggest to use jq - link

pkg_ver=$(jq '.version' package.json)

However, if you have only this two items then maybe using sed, awk or tr would be easier.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download