epcim
3/23/2017 - 8:38 PM

jq parser examples

jq parser examples


# This produces a list of paths in the input:
jq -c 'path(..)|[.[]|tostring]|join("/")'
  
# Parse salt status output
jq -r 'to_entries | map({ key:.key, value: { total: [.value[]]|length ,\
                                       succeed: [.value[]|select(.result == true)]|length,\
                                       failed:  [.value[]|select(.result == false)]|length,\
                                       changes: [select(.value[].changes|length > 0)]|length  }}) | from_entries ' 
 
 # Grep some pattern on the random path                               
 jq -e "..|${PATTERN}| select(.!=null)"
 
 # Partial patch match
 '.compute?.network