Using jq with bash to run command for each object in array

Your best bet is probably to output each record in something like TSV format, then read that from a shell loop.

jq -r '.[]|[.user, .date, .email] | @tsv' |
  while IFS=$'\t' read -r user date email; do
    mycommand -u "$user" -d "$date" -e "$email"
  done

jq itself doesn’t have anything like a system call to run an external command from within a filter, although it seems that they are working on it.

Leave a Comment