Skip to content

Instantly share code, notes, and snippets.

@navono navono/jsonParser.sh
Created May 21, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.