bash-为JSON文件执行命令中的每个值

时间:2018-02-26 18:33:12

标签: json bash curl jq

我有json文件(1.json),我可以遍历它来查找项目,父键和自定义字段

jq -r '.issues[] | .key' 1.json
jq -r '.issues[] | .fields.project.key' 1.json
jq -r '.issues[] | .fields.customfield_10107.id' 1.json

输出:

TECH-540
TECH-531
TECH-627
TECH-538
TECH-577
TECH-572
TECH-520
TECH-565
TECH-567
TECH
TECH
TECH
TECH
TECH
TECH
TECH
TECH
TECH
10400
10400
10400
10400
10400
10400
10400
10400
10400

我想将TECH-XXX存储到project = jq -r '.issues[] | .key' 1.json TECH到父= jq -r '.issues[] | .fields.project.key' 1.json 10400到custom_field = jq -r '.issues[] | .fields.customfield_10107.id' 1.json 变量 对于1.json文件中找到的每个值,执行for循环代码(在这种情况下运行curl 9次):

curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"$project\"},\"parent\":{\"key\":\"$parent\"},\"summary\":\"Test ChargenNr\",\"description\":\"some description\",\"issuetype\":{\"name\":\"Sub-task\"},\"customfield_10107\":{\"id\":\"$custom_field\"}}}" -H "Content-Type:application/json" https://jira.company.com/rest/api/latest/issue/

0 个答案:

没有答案