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
-
[.[]|.nameWithOwner] // ["KyleMit/stack-posts","KyleMit/HelloSERN"]
-
[.[]|.defaultBranchRef.name] // ["main","master"]
But can't quite get how to combine fields / selectors to return mulitple values