json - How do I mix jq operators? -


i'm using jq analyze json content via bash. works far.

now, have content:

{ "_id" : { "$oid" : "55a3fb74e4b0feb11ba5bec2" },  "alertid" : 15, "headline" : "license xxxxxx expire",  "includeditems" : []} 

now use jq alertid , headline, so:

jq .alertid,.headline filename

but, want add count of items in includeditems array. so:

jq '.includeditems | length' filename

this work, need part of 1 command. reason filename file huge amount of json , if run commands separately, i'd spend lot of time trying thread outputs together. instead, hoping find way achieve this:

jq .alertid,.headline,'.includeditems | length' filename

but doesn't work.

the problem '.alertid,.headline,.includeditems | length' , has higher precedence |, it's equivalent '(.alertid,.headline,.includeditems) | length'. since want | have higher precedence — want .includeditems | length single list-item — need group parentheses:

jq '.alertid, .headline, (.includeditems | length)' filename 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -