Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if adminLock = 1 take the median "domains", how do I write, in the stitching array

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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" )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading