I'm trying to simplify a nested JSON structure using JQ

Input

[
  {
    "defaultBranchRef": {
      "name": "main"
    },
    "nameWithOwner": "KyleMit/stack-posts"
  },
  {
    "defaultBranchRef": {
      "name": "master"
    },
    "nameWithOwner": "KyleMit/HelloSERN"
  }
]

Desired Output

[
  {
    "nameWithOwner": "KyleMit/stack-posts",
    "defaultBranchName": "main"
  },
  {
    "nameWithOwner": "KyleMit/HelloSERN",
    "defaultBranchName": "master"
  }
]

Attempted Solution

I can retrieve each of the individual fields at any depth

But can't quite get how to combine fields / selectors to return mulitple values

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