JQ Tutorial
JQ Tutorial
Learn jq, the command-line JSON processor, one exercise at a time.
jq lets you slice, filter, map, and transform JSON straight from the command line — no script required for most everyday tasks like pulling a field out of an API response or reshaping a config file.
This tutorial walks through jq's core building blocks — identity, field access, indexing and slicing, pipes, and filters — with a real input and expected output for every step. You type an expression, we check it against jq's actual output, so what you learn here works exactly the same in your terminal.
What you'll practice (27 steps)
- Identity: .
- Object field: .foo
- Nested fields: .foo.bar
- Bracket keys: .["foo"]
- Optional access: .foo?
- Array index: .[0]
- Slice: .[1:3]
- Iterate: .[]
- Pipe: |
- Comma: ,
- Collect into an array: [ ]
- Build objects: {a, b}
- Rename keys: {new: .old}
- Computed values: {k: (expr)}
- String interpolation: \(expr)
- Inspect: keys, length, has
- Filter with select()
- Transform with map()
- map(select(...)) — filter arrays
- Order: sort_by, unique
- Bucket with group_by()
- Aggregate with add
- Reshape: to_entries / from_entries
- Fold with reduce
- Defaults: the // operator
- Recursive descent: ..
- Capstone: put it together