我有一个 json 文件,我需要读取它并将一个附加值(字符串)写回对象的根目录。有没有办法从命令行做到这一点?我找到了一个名为 JQ的实用程序,但有点不清楚我们如何将这些值写回。这是对象 JSON 对象的示例。json 树并不重要,因为我只想将字符串注入到 json 对象的根目录中。
{"widget": {
"debug": "on",
"window": {
"height": 500
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
回写的 json 应该是这样的:
{
"Category": "Unknown",
"widget": {
"debug": "on",
"window": {
"height": 500
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}