JQ选择名称显示id

时间:2018-05-09 15:52:30

标签: json jq

我认为这几乎是正确的我只是错过了一块,如果我选择Atlas我想要显示Id

echo "${json}" |jq '.[] | select(.name=="atlas" | .id)'

JSON

[
  {
    "name": "atlas",
    "id": 2314430,
    "slug": "atlas",
    "description": "",
    "privacy": "closed",
    "url": "https://api.github.com/teams/2314430",
    "members_url": "https://api.github.com/teams/2314430/members{/member}",
    "repositories_url": "https://api.github.com/teams/2314430/repos",
    "permission": "pull"
  },
  {
    "name": "HAL",
    "id": 2318635,
    "slug": "hal",
    "description": "",
    "privacy": "closed",
    "url": "https://api.github.com/teams/2318635",
    "members_url": "https://api.github.com/teams/2318635/members{/member}",
    "repositories_url": "https://api.github.com/teams/2318635/repos",
    "permission": "pull"
  }
]

1 个答案:

答案 0 :(得分:1)

我把酒吧放在了错误的一边

jq '.[] | select(.name=="atlas") | .id'