Skip to content

Instantly share code, notes, and snippets.

@jaredhoward
Created October 23, 2015 22:21
Show Gist options
  • Save jaredhoward/a72b5e67ab20a0c00042 to your computer and use it in GitHub Desktop.
Save jaredhoward/a72b5e67ab20a0c00042 to your computer and use it in GitHub Desktop.
jq Examples

jq Examples

jq is a lightweight and flexible command-line JSON processor.

The examples that I'm placing here are to help remind me how to do some parsing.

Flatten when the flatten function doesn't exist.

echo -e '["foo","bar"]\n["foo","fizz","buzz"]' | jq -c -s 'map(.[])'

Flatten with filtering then unique.

echo '{"request":"hello","query":{"foo":"bar","hello":"there"}}
{"request":"bye","query":{"not":"nogood"}}
{"request":"hello"}
{"request":"hello","query":{"foo":"bar","fizz":"buzz"}}' | \
jq -c -s 'map(select(.request=="hello" and .query) | .query | keys) | map(.[]) | unique'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment