Reputation: 10846
I have a json file and I need to read it and write back an additional value (string) to the root of the object. Is there any way to do that from the command line? I've found an utility named JQ but it's a bit unclear how we can write the values back. Here is a sample of the object JSON object. The json tree is unimportant as I'm interested only to inject the string only into the root of the json object.
{"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;"
}
}}
The json written back should look like this:
{
"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;"
}
}
}
Upvotes: 0
Views: 1778
Reputation: 134841
Just set the new field directly using simple assignment.
.Category = "Unknown"
Upvotes: 1