* Simple introduction [[https://tecadmin.net/linux-jq-command/#:~:text=The%20JQ%20command%20is%20used,data%20from%20a%20JSON%20file|External_Link]] * Medium introduction [[https://lzone.de/cheat-sheet/jq|External_Link]] * Excellent/complex examples of jq filters : [[https://github.com/ipspace/docker-examples/tree/d8599f8b4e44b24cc50afafd8a56438ab31bf80b/filter]] jq . # the dots means 'applies for all objects below' For __Docker__:\\ networks: aws ec2 describe-subnets | jq .[] | jq .[].Ipv6CidrBlockAssociationSet | jq .[].Ipv6CidrBlockState # nested jq (two levels here) aws ec2 describe-regions | jq -r "[[.Regions[].RegionName]]" aws ec2 describe-vpcs | jq -r "[[.Reservations[].Instances[].InstanceId]]" # extract all instances id (down 3 levels) aws ec2 describe-vpcs | jq -r '.Vpcs | length' # COUNT number of VPCs aws ec2 describe-vpcs --region eu-west-1 | jq -r '.Vpcs | length' # For a DIFFERENT Region cat response.json | jq .data | jq -r '.[].relationships.managed_object.data.id' cat response.json| jq .data | jq -r '[.[].relationships.managed_object.data.id + " " + .[].attributes.alert_type]' # two fields cat response.json| jq '.data | .[] | .attributes' # strips 'data' values for all 'attributes' keys cat response.json| jq '.data | .[] | .attributes.subobject.dns_scoping' PRETTY TABLE FORMAT:\\ aws ec2 describe-instances \ --query 'Reservations[*].Instances[*].{Instance:InstanceId,Name:Tags[?Key==`Name`][0].Value,Private:PrivateIpAddress,Public:PublicIpAddress}' \ --filters "Name=instance-state-name,Values=running" \ --output table {{:virtualization:cloud:aws-cli-query.jpeg?900|}} Lists the public IPs (querying the OCI DNS): oci dns record zone get --zone-name-or-id oci.mycompany1.co.uk | jq -r '.[].items[] | .domain + " " + .rdata' oci dns record zone get --zone-name-or-id lhr.oci.mycompany1.co.uk | jq -r '.[].items[] | .domain + " " + .rdata' oci compute instance get --instance-id ocid1.instance.oc1.uk-london-1.anwgiljrgghpcsic6lrm3u5zqh7vwqqvsv44ewyjybis3lzhhb7bqmizelrq | jq -r '.data | .["display-name"]' # how to extract the keys that OCI annoying put hyphens in rather than underscores oci network vcn list --region=eu-frankfurt-1 --compartment-id=$cs | jq -r '.data[] | .["compartment-id"]' Folsom: cat /home/jaime/Downloads/response.json | jq -r '.response[].attributes | .display_name ' > /home/jaime/Downloads/response1.json * response is 1st level, and has many 'string' elements under it * which are attribute blocks * | now stuff inside the 'block' oci compute instance list --compartment-id=$cb | jq -r '.data[]|select (."display-name"=="pepe37.lhr.oci.mycompany1.co.uk")' oci compute instance list --compartment-id=$cb | jq -r '.data[]|select (."display-name" | contains("cc0"))' # like regex 'contains' This filters with id but extracts the pair, not the key [[https://til.hashrocket.com/posts/uv0bjiokwk-use-jq-to-filter-objects-list-with-regex]] \\ oci network nsg list --region us-phoenix-1 --compartment-id ocid1.compartment.oc1..aaaaaaaax5zpuw6ggeudpiqueidy5xlqentk2ngs7p6445an34mgwlrpbccq | jq -r '.data[] | ."defined-tags"."NetworkSecurity"."groupId" + ": " + .id' \\ Formatted output with my own labels [[https://my.ipspace.net/bin/get/DockerNet/Docker%20Networking%20Deep%20Dive.pdf?doccode=DockerNet|External Link]]:\\ .[]|{ Name, Gateway: .IPAM.Config[]|.Gateway, Endpoints: [ .Containers|to_entries[]|{ Name: .value.Name, IPv4: .value.IPv4Address } ] } docker network inspect bg0 | jq -f myfilterabove * ''to_entries'' and ''from_entries'' to convert between objects and key-value pair arrays