How to modify a key's value in a JSON file fro

2019-01-28 07:21发布

Is it possible to change the value of a key in a JSON file from command line?

e.g., in package.json:

Change

{
    ...
    ...
    "something": "something",
    "name": "idan" 
    ...
}

To

{
    ...
    ...
    "something": "something",
    "name": "adar" 
    ...
}

1条回答
啃猪蹄的小仙女
2楼-- · 2019-01-28 07:58

One way to achieve it is by using the "json" npm package, e.g.:

json -I -f package.json -e "this.name='adar'"

Another way is by using the jq CLI, e.g.:

mv package.json temp.json
jq -r '.name |= "adar"' temp.json > package.json
rm temp.json
查看更多
登录 后发表回答