jq not working on tag name with dashes and numbers

You need to enclose in brackets and double quotes:

jq '."component-status"'

With your given input it returns:

[
  {
    "status": "OK",
    "component": "Service1",
    "status-code": 200
  },
  {
    "status": "OK",
    "component": "Service2",
    "status-code": 200
  }
]

The jq Manual (development) –> Basic filters:

.foo, .foo.bar

The simplest useful filter is .foo. When given a JSON object (aka
dictionary or hash) as input, it produces the value at the key “foo”,
or null if there’s none present.

If the key contains special characters, you need to surround it with
double quotes like this: ."foo$".

From the github issue Cannot select field if field name has dashes:

Currently, that gets parsed as a subtraction. You can always
explicitly use strings for when your keys don’t fit identifier syntax.

Leave a Comment