I'm very new at this and I am trying to filter the following nested json key using jq
`
{
"team": {
"id": "PI6MJXZ",
"name": "my_team",
"description": null,
"type": "team",
"summary": "my_team",
"self": "https://someurl.com/my_teams/ID",
"html_url": "https://someurl.com/my_teams/ID",
"default_role": "manager",
"parent": null
}
}
`
However when I run the following jq filter jq '.team[]'
I get the following output:
`
"PI6MJXZ"
"my_team"
null
"team"
"my_team"
"https://someurl.com/my_teams/ID"
"https://someurl.com/my_teams/ID"
"manager"
null
`
I know that this is running as intended as I am testing this out on this jq filter tool
My question is, how can I go about filtering one specific key within this nested json key?
What I am looking for using the above example is to output only the following:
"PI6MJXZ"
So it should go team ---> id
Any help with some explanation as to how one can do this and for a more advanced nested filter would be greatly appreciated!
CodePudding user response:
My question is, how can I go about filtering one specific key within this nested json key?
Are you trying to update |=
a field (.team
) by setting it to one of its own fields (.id
)?
jq '.team |= .id'
{
"team": "PI6MJXZ"
}