jq is a lightweight, flexible command-line JSON processor written in portable C with zero runtime dependencies. Every jq program is a filter β it takes a JSON input and produces one or more JSON outputs. Filters are composed with | (pipe) and , (multiple outputs). jq is available on Linux, macOS, and Windows and is a staple of shell scripting for working with APIs, Kubernetes, Docker, AWS CLI, and any JSON data stream.
What This Cheat Sheet Covers
This topic spans 15 focused tables and 200 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1 β Invocation Flags and Basic Syntax
Before you write any filter, these are the command-line knobs that shape how jq reads input and prints output. The ones you'll use constantly are -r for raw (unquoted) strings, -c for compact one-line output, and -n/-s for controlling whether jq reads stdin at all or slurps it into a single array. The identity filter . and the | and , operators at the bottom are the two building blocks every larger filter is composed from.
| Flag / Syntax | Example | Description |
|---|---|---|
echo '{"a":1}' | jq '.' | β’ Pass input through unchanged β’ pretty-prints by default | |
jq -c '.' | Compact (minified) output β no whitespace | |
jq -r '.name' | Print strings without JSON quotes | |
jq -j '.a, .b' | Like -r but no trailing newline between outputs | |
jq -n '{"x":1}' | β’ Don't read stdin β’ useful for constructing JSON from scratch | |
jq -s '.[0]' | Read all inputs into one array before filtering | |
jq -R '.' | Read each line as a raw string (not JSON) | |
jq -e '.ok' | Exit 1 if last output is false or null |