作者:手机用户2502926851 | 来源:互联网 | 2023-01-08 13:46
我正试图用这一行改变多个json值
jq '.two="newval", .three="newval"' my.json
这是输入
{
"one": {
"val": 1
},
"two": "val",
"three": "val",
"four": "val"
}
但输出是2 jsons:
{
"one": {
"val": 1
},
"two": "newval",
"three": "val",
"four": "val"
}
{
"one": {
"val": 1
},
"two": "val",
"three": "newval",
"four": "val"
}
如何在一个项目中更改多个值和输出?
1> peak..:
只需将逗号更改为竖线字符就可以了:
.two="newval" | .three="newval"
","用于连接流:A,B
将发出A然后发出B.
2> jq170727..:
这是一种使用+对象添加来更新多个成员的方法。
. + {two:"newtwo", three:"newthree"}
样本运行(假设中的数据data.json
)
$ jq -M '. + {two:"newtwo", three:"newthree"}' data.json
{
"one": {
"val": 1
},
"two": "newtwo",
"three": "newthree",
"four": "val"
}
在jqplay.org上在线尝试