首页 > 解决方案 > JQ select name 显示id

问题描述

我认为这几乎是正确的我只是缺少一块,如果我选择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"
  }
]

标签: jsonjq

解决方案


我把酒吧弄错了

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


推荐阅读