0

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;"
    }
  }
}

1 Answer 1

1

Just set the new field directly using simple assignment.

.Category = "Unknown"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.