jq JSON Processor - BKJackson/BKJackson_Wiki GitHub Wiki

jq Home
jq Documentation

Example jq commands (From tutorial)

# Save GitHub Commits JSON data to a local file
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' > test.json

# View JSON data pretty-printed with jq
cat test.json | jq '.' 

# Use jq to extract first element in JSON array
cat test.json | jq '.[0]'

# Look at a limited number of JSON fields
# The output is a jq object. 
cat test.json | jq '.[0] | {message: .commit.message, name: .commit.committer.name}'

# Look at JSON fields for all elements in the array
cat test.json | jq '.[] | {message: .commit.message, name: .commit.committer.name}'

# Collect output as a single csv array with brackets []
cat test.json | jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'

# Grab multiple "html_url" fields inside the array of parent commits
cat test.json | jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'