Extract child key and flatten into parent object output in JQ

Just update |= the defaultBranchRef field to the content of its name subfield:

jq '.[].defaultBranchRef |= .name'
[
  {
    "defaultBranchRef": "main",
    "nameWithOwner": "KyleMit/stack-posts"
  },
  {
    "defaultBranchRef": "master",
    "nameWithOwner": "KyleMit/HelloSERN"
  }
]

Demo

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top