#1: For input file that contains JSON object per row, wherein objects contains key K1 and its value V1 as another object. V1 contains key K1_1 with multiple values. requirement is to find rows where count of value(s) of K1_1 is more than 2.
jq "select( .K1.K1_1|length >= 2).K1.K1_1" <INPUT_FILE>
#2: Filter objects that contain specific key&value from file that contains JSON objects per line..
jq 'select(.[]|.key=="value")' <INPUT_FILE>
#3: Print value of specific key in object:
**Try executing echo part first, to see data that will be sent to jq in following commands.
jq '.key' <INPUT_FILE>
or
echo "{\"a\":10, \"b\":12}" | jq '.b'
#4: Print concatenated values of multiple keys : #using tostring for integer values..
echo "{\"a\":10, \"b\":12}" | jq '(.b|tostring) + "--" +(.a|tostring)'
#5: Print sum of values of multiple keys :
echo "{\"a\":10, \"b\":12}" | jq '.b + .a'
#6: Nested objects, arrays and more. Expects each line is array of coordinate objects.
json='[{"x":1,"y":2}, {"x":60,"y":90}]\n[{"x":0,"y":0},{"x":10,"y":10}]'
#6.1: Find distance between each points. Sources : distance-formula,
echo -e $json | jq '{x:(.[1].x - .[0].x), y:(.[1].y - .[0].y)} | "distance : " + (((.x*.x) + (.y*.y)) | sqrt | tostring )'
Shameless SEO terms: