Home > Net >  bash shell JSON JQ if adminLock =1 Take the median "domains", how do I write
bash shell JSON JQ if adminLock =1 Take the median "domains", how do I write

Time:11-08

if adminLock = 1 Take the median "domains", how do I write

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

I hope to get your help, because I really need it, and the complete crawling code. I am good at using Bash Shell,jq -r code

CodePudding user response:

You can select all domains where adminLock == 1 of the inner array with this code:

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

Output

xxx2.com
xxx4.com

CodePudding user response:

I want to take the value xxx1.com, groupid combination into an array, how should I do Want to get such a result

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

How should I do thank you

  • Related