I want to take the value xxx1.com, the group value of the group into an array, how should I do want to get such a result
{ "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
now_array=(["173652434"]="xxx2.com" ["173205812"]="xxx4.com")
The result I want is like this
CodePudding user response:
I'm not sure if I understand your question correctly, but here's how to use jq to filter that JSON according to afield value, then format it to create an associative array in Bash:
$ declare -A now_array="($(jq -r '
.data.data[] | select(.adminLock == 1) | @sh "[\(.domainsID)]=\(.domains)"
' input.json))"
$ echo "${now_array["173205812"]}"
xxx4.com
$ declare -p now_array
declare -A now_array=([173652434]="xxx2.com" [173205812]="xxx4.com" )