如何通过命令行在JSON文件中修改密钥的值 [英] How to modify a key's value in a JSON file from command line
本文介绍了如何通过命令行在JSON文件中修改密钥的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从命令行更改JSON文件中key
的value
?
Is it possible to change the value
of a key
in a JSON file from command line?
例如,在package.json中:
e.g., in package.json:
更改
{
...
...
"something": "something",
"name": "idan"
...
}
收件人
{
...
...
"something": "something",
"name": "adar"
...
}
推荐答案
一种实现方法是使用"json" npm程序包,例如:
One way to achieve it is by using the "json" npm package, e.g.:
json -I -f package.json -e "this.name='adar'"
另一种方法是使用 jq CLI ,例如:
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
这篇关于如何通过命令行在JSON文件中修改密钥的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文