Home > Mobile >  Process JSON with key name containing brackets
Process JSON with key name containing brackets

Time:09-17

I have the following JSON

{
    "jps": {
      "onInstall": [{
        "cmd [sqldb]": [
            "command"
        ]
      }]
    }
  }

Without [sqldb], I was doing the query as follows:

jq '.jps.onInstall.cmd=["long line", "another line"]' my-app.json

And it worked, but with [sqldb], how can I translate it to jq query format?

I tried

jps.onInstall.cmd\[sqldb\] and jps.onInstall.cmd.sqldb but no luck

CodePudding user response:

The problem is not with the special character "cmd [sqldb]" but with your onInstall type, which is a list type, but you are missing the .[] indicator

.jps.onInstall[]."cmd [sqldb]" = ["long line", "another line"]

or

.jps.onInstall[]["cmd [sqldb]"] = ["long line", "another line"]
  • Related