【发布时间】:2015-02-25 18:53:21
【问题描述】:
我有一个 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;"
}
}
}
【问题讨论】:
标签: json bash command-line-interface jq