solemnify solemnify - 1 year ago 111
JSON Question

Running bash commands for each JSON item through jq

I would like to run a bash command for each field in a JSON formatted piece of data by leveraging jq.

"apps": {
"firefox": "1.0.0",
"ie": "1.0.1",
"chrome": "2.0.0"

Basically I want something of the sort:

foreach app:
echo "$key $val"

Answer Source

Assuming you wanted to list out the key/values of the apps object:

$ jq -r '.apps | to_entries[] | "\(.key)\t\(.value)"' input.json
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download