bash shell JSON JQ如果adminLock =1取中值“域”,怎么写

tpgth1q7  于 2022-11-19  发布在  Shell
关注(0)|答案(1)|浏览(133)

如果adminLock = 1取中值“域”,怎么写

{
  "code": 0,
  "message": "成功",
  "data": {
    "recordCount": "128",
    "pageSize": 100,
    "page": 1,
    "pageCount": 2,
    "data": [
      {
        "domainsID": "173652434",
        "nsGroupID": "199",
        "groupID": "78987",
        "domains": "xxx1.com",
        "state": 3,
        "userLock": 0,
        "adminLock": 0,
        "view_type": "1"
      },
      {
        "domainsID": "173652434",
        "nsGroupID": "199",
        "groupID": "78987",
        "domains": "xxx2.com",
        "state": 3,
        "userLock": 0,
        "adminLock": 1,
        "view_type": "1"
      },
      {
        "domainsID": "173205836",
        "nsGroupID": "199",
        "groupID": "78987",
        "domains": "xxx3.com",
        "state": 3,
        "userLock": 0,
        "adminLock": 0,
        "view_type": "1"
      },
      {
        "domainsID": "173205812",
        "nsGroupID": "199",
        "groupID": "78987",
        "domains": "xxx4.com",
        "state": 3,
        "userLock": 0,
        "adminLock": 1,
        "view_type": "1"
      }
    ],
    "nextPage": 2
  }
}

我希望得到你的帮助,因为我真的很需要它,以及完整的爬行代码。我擅长使用Bash Shell,jq -r代码

我想把值xxx1.com,groupid组合成一个数组,我该怎么做想得到这样的结果

now_array=(["173652434"]="xxx2.com" ["173205812"]="xxx4.com")

我该怎么感谢你

dluptydi

dluptydi1#

您可以使用以下代码选择内部数组的所有domains,其中adminLock == 1

jq -r '.data.data[] | select(.adminLock == 1) | .domains' "$INPUT"

输出

xxx2.com
xxx4.com

相关问题