Christoph's 2 Cents

A Backup for My Brain!

CloudDevOpsOracle Cloud InfrastructrureOracle Linux

OCI JQ tricks

Here are a few examples for using jq to filter and slice JSON data returned from the OCI CLI.
These techniques will work with any type of JSON responses. Make sure to validate the name for the top array. OCI CLI names that array data. Other JSON responses may have a different name.

oci iam region list |
\
jq -c '.data[] | select(.name | startswith("us")) | .name'
oci compute image list \
-c ocid1.compartment.xxx | jq '.data[]["display-name"]'
oci compute image list \
  -c ocid1.compartment.xxx | \
  jq '.data[]["display-name"] | \
  select(startswith("Oracle-Linux")) | 
  select(contains("GPU"))'
oci compute image list \
  -c ocid1.compartment.xxx| \
  jq '.data[] | \
  select(.["display-name"] | \
  startswith("Oracle-Linux")) | \
  select(.["display-name"] | \
  contains("GPU") | not ) | \
  .["display-name"], .id'
oci compute instance list --all \
  -c ocid1.compartment.xxx | \
  jq '.data[] | \
  select(.["defined-tags"].Schedule) '