Jq – select an attribute beginning with a string

jqjson

input json:

[
  {
    "id": "89",
    "hostname": "abcd"
  },
  {
    "id": "89",
    "hostname": "babcd"
  }
]

How to modify below filter to get on output only hostname beginning with "abcd"?

$ jq -r '.[]|select(.hostname | contains("abcd"))' jjjj
{
  "id": "89",
  "hostname": "abcd"
}
{
  "id": "89",
  "hostname": "babcd"
}
$ jq -r '.[]|select(.hostname | contains("^abcd"))' jjjj
$

Best Answer

Solution:

jq -r '.[]|select(.hostname | startswith("abcd"))' jjjj
Related Question