Bash-jq-examples

From I Will Fear No Evil
Revision as of 15:19, 3 December 2021 by Chubbard (talk | contribs) (Created page with "Some examples of using jq to do filtering.. <pre> raw jason: { "1": [ { "id": "123456789", "accountId": "a1-supplies-01234", "accountName": "a1-suppli...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Some examples of using jq to do filtering..

raw jason:
{
  "1": [
    {
      "id": "123456789",
      "accountId": "a1-supplies-01234",
      "accountName": "a1-supplies",
      "status": "LIVE",
      "customerId": "A1 Supplies",
      "customerType": "display"
    }
  ]
}
Map will iterate through the array(s) looking for key status, and value LIVE
<json here> | jq  -c 'map(select(.[].status | contains ("LIVE")))' | jq
  • Running the output through jq again puts the line breaks back in place
  • contains in a search DOES honor pipes
 contains ("LIVE"|"DEAD") 

Stackoverflow details