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 SyntaxTable 2 β Field Selection and Object ConstructionTable 3 β Array Indexing, Slicing, and IterationTable 4 β Aggregation and SortingTable 5 β String Functions and InterpolationTable 6 β Regular ExpressionsTable 7 β Variables, Arguments, and EnvironmentTable 8 β Format Strings and Output FormattersTable 9 β Paths and Update OperatorsTable 10 β Conditionals, Comparisons, and Boolean LogicTable 11 β Recursive Descent and Advanced TraversalTable 12 β Custom Functions and ModulesTable 13 β Math and Date FunctionsTable 14 β Real-World Pipelines and Tool IntegrationTable 15 β Shell Quoting, Common Pitfalls, and Tool Comparisons
Table 1 β Invocation Flags and Basic Syntax
| 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 |