JQ Cheatsheet
Loop over JSON arrayThis example will print all of the values associated with the name key:sample='[ 0001-1-1 08:0:0 Author: techvomit.net(查看原文) 阅读量:0 收藏

Loop over JSON array

This example will print all of the values associated with the name key:

sample='[{"name":"foo"},{"name":"bar"}]'
for row in $(echo "${sample}" | jq -r '.[] | @base64'); do
    echo ${row} | base64 --decode | jq -r '.name'
done

Resource: https://www.starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/

Get object based on value of JSON variable

jq '.[] | select(.location=="Stockholm")' json
{
  "location": "Stockholm",
  "name": "Walt"
}
{
  "location": "Stockholm",
  "name": "Donald"
}

Resource: https://stackoverflow.com/questions/18592173/select-objects-based-on-value-of-variable-in-object-using-jq

Get keys of object

Get values of array object

jq '.[] | values' blob.json

文章来源: https://techvomit.net/jq/
如有侵权请联系:admin#unsafe.sh