我有一个需要在某种条件下更新的json文件.
示例json
{
"Actions" : [
{
"value" : "1",
"properties" : {
"name" : "abc",
"age" : "2",
"other ": "test1"
}
},
{
"value" : "2",
"properties" : {
"name" : "def",
"age" : "3",
"other" : "test2"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在编写一个脚本,它使用Jq匹配值和更新,如下所示
cat sample.json | jq '.Actions[] | select (.properties.age == "3") .properties.other = "no-test"'
Run Code Online (Sandbox Code Playgroud)
输出(打印到终端)
{
"value": "1",
"properties": {
"name": "abc",
"age": "2",
"other ": "test1"
}
}
{
"value": "2",
"properties": {
"name": "def", …
Run Code Online (Sandbox Code Playgroud)