How to modify a key's value in a JSON file from command line

前端 未结 2 1872
再見小時候
再見小時候 2020-12-15 06:06

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

e.g., in package.json:

Change

{
    .         


        
2条回答
  •  不思量自难忘°
    2020-12-15 06:52

    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
    

提交回复
热议问题