Skip to content

Instantly share code, notes, and snippets.

@sloanlance
Created September 29, 2023 15:18
Show Gist options
  • Save sloanlance/7089d59bd986a8af4eaf7947e17c4329 to your computer and use it in GitHub Desktop.
Save sloanlance/7089d59bd986a8af4eaf7947e17c4329 to your computer and use it in GitHub Desktop.
Useful notes about using jq

jq Notebook

Useful notes about using jq.

  1. Print all paths to values
    • jq -c paths Prints each path as an array and doesn't show values.
    • jq --stream 'select(.[1]|scalars!=null) | "\(.[0]|join(".")): \(.[1]|tojson)"' example.json
      Nearly perfect. If each path shown began with . and array indices were enclosed in square brackets, then each one would be a valid jq query string.
    • jq -r 'paths(scalars) as $p | $p + [getpath($p)] | join(".")'
      Prints dot-delimited paths concatenated with values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment