简体   繁体   中英

parsing nested json keys with jq

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!

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"
}

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM