using jq to assign multiple output variables

You can use separate variables with read : read var1 var2 var3 < <(echo $(curl -s ‘https://api.github.com/repos/torvalds/linux’ | jq -r ‘.id, .name, .full_name’)) echo “id : $var1” echo “name : $var2” echo “full_name : $var3” Using array : read -a arr < <(echo $(curl -s ‘https://api.github.com/repos/torvalds/linux’ | jq -r ‘.id, .name, .full_name’)) echo “id : … Read more

Reusable function to group_by but return an object with group as key

Here’s a variant using reduce instead of group_by: reduce .[] as $m ({}; .[$m.country] += [$m]) Demo Or as a defined function: def grp(f): reduce .[] as $m ({}; .[$m|f] += [$m]); grp(.country) Demo { “germany”: [ { “name”: “anna”, “country”: “germany” }, { “name”: “lisa”, “country”: “germany” } ], “usa”: [ { “name”: “john”, … Read more

Exporting JSON to environment variables

Borrowing from this answer which does all of the hard work of turning the JSON into key=value pairs, you could get these into the environment by looping over the jq output and exporting them: for s in $(echo $values | jq -r “to_entries|map(\”\(.key)=\(.value|tostring)\”)|.[]” ); do export $s done If the variables being loaded contain embedded … Read more

Get outputs from jq on a single line

-c is what you likely need Using the output you posted above, you can process it further: jq -c . input To Give; {“key”:”SEA-739″,”status”:”Open”,”assignee”:null} {“key”:”SEA-738″,”status”:”Resolved”,”assignee”:”user2@mycompany.com”} Or you can just change your original command FROM jq -r ‘(.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress})’ TO jq -c ‘(.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress})’

tech