我有JSON文件
{
"fields":
{
"project":
{
"key": "TECH"
},
"parent":
{
"key": "TECH-456"
},
"summary": "Sub-task of TEST-456",
"description": "Don't forget to do this too.",
"issuetype":
{
"id": "5"
}
}
}
我希望输出parent ='aaaaa'进入
"parent":
{
"key": "variable value=$parent"
},
并输出project ='bbbb'
投入
"project":
{
"key": variable value=$project
},
我正在尝试使用jq jq -n --arg $ ja'。fields.project.key = $ ja'my.json但收到错误
答案 0 :(得分:0)
批量试用&错误终于得到了它:
project=`jq -r '.issues[0] | .key' 1.json`
parent=`jq -r '.issues[0] | .fields.project.key' 1.json`
cat my.json | jq --arg project "$project" '.fields.project.key=$project' | jq --arg parent "$parent" '.fields.parent.key=$parent'>aa.json