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

前端 未结 5 1500
眼角桃花
眼角桃花 2021-02-02 07:48

How can I run a Bash command for every JSON object in a JSON array using jq? So far I have this:

cat credentials.json | jq -r \'.[] | .user, .date, .         


        
5条回答
  •  迷失自我
    2021-02-02 08:44

    I came across the same problem recently where xargs doesn't help that much due to the relatively complicated set of arguments I wanted to pass around. Thus I implemented an sh filter (and its friends) to jq. I haven't yet had enough time to write documentation and tests for it so not creating a PR for it to become a part of the official codebase yet. So now it's only for the ones who are willing to compile this version themselves:

    https://github.com/haochenx/jq/tree/sh-support

提交回复
热议问题