Skip to content

Instantly share code, notes, and snippets.

@navono
Created May 21, 2019 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navono/640ce395e230e579c72a6348e4507aa9 to your computer and use it in GitHub Desktop.
Save navono/640ce395e230e579c72a6348e4507aa9 to your computer and use it in GitHub Desktop.
parse json with jq in shell
// {
// "sync": true,
// "machines": [
// {
// "name": "1911-1",
// "address": "192.168.1.14",
// "user": "administrator",
// "passwd": "supcon_1",
// "path": "C:\\AppDev"
// },
// {
// "name": "1911-2",
// "address": "192.168.1.15",
// "user": "administrator",
// "passwd": "supcon_1",
// "path": "C:\\AppDev"
// }
// ]
// }
filename=deploy.json
sync=$(jq '.sync' $filename)
if [ $sync == false ]; then
echo "exit"
else
count=$(jq -r '.machines | length' $filename)
count=$((count-1))
for i in $( eval echo {0..$count} ); do
value=$(jq -r ".machines[$i]" $filename);
name=$(jq -r '.name' <<< "$value");
address=$(jq -r '.address' <<< "$value");
echo $address
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment