A lightweight and flexible command-line JSON processor.

# To output a JSON file, in pretty-print format:
jq . <file.json>

# To output all elements from arrays (or all the values from objects) in a JSON file:
jq '.[]' <file.json>

# To read JSON objects from a file into an array, and output it (inverse of 'jq .[]'):
jq --slurp . <file.json>

# To output the first element in a JSON file:
jq '.[0]' <file.json>

# To output the value of a given key of the first element in a JSON text from 'stdin':
cat <file.json> | jq '.[0].<key_name>'

# To output the value of a given key of each element in a JSON text from 'stdin':
cat <file.json> | jq 'map(.<key_name>)'

# To output the value of multiple keys as a new JSON object (assuming the input JSON has the keys 'key_name' and 'other_key_name'):
cat <file.json> | jq '<{my_new_key>: .<key_name>, <my_other_key>: .<other_key_name>}'

# To combine multiple filters:
cat <file.json> | jq 'unique | sort | reverse'

# To output the value of a given key to a string (and disable JSON output):
cat <file.json> | jq --raw-output '"some text: \(.<key_name>)"'