Consuming REST APIs with curl and jq Together
Chain curl requests into jq to extract, paginate, and reformat live API responses in scripts.
Why curl + jq Is the Power Combo
REST APIs return JSON. curl fetches the raw response; jq slices, filters, and reshapes it — all in a single pipeline. No Python script, no Postman, no intermediate file needed.
- curl handles HTTP: methods, headers, auth, redirects.
- jq handles JSON: filtering, mapping, transforming, formatting.
- Piping them together creates concise, composable API workflows.
This lesson builds that skill from first principles through real-world pagination and scripting patterns.
Basic curl Pipeline into jq
The simplest pattern: pipe curl output directly into jq. Use -s (silent) to suppress curl's progress meter so only the JSON body reaches jq.
-s— silent mode, no progress bar..— jq's identity filter; pretty-prints the full response.-ron jq — raw output (no surrounding quotes on strings).
#!/usr/bin/env bash
# Fetch a public endpoint and pretty-print the JSON
curl -s 'https://jsonplaceholder.typicode.com/todos/1' | jq '.'
# Extract just the title field as a plain string
curl -s 'https://jsonplaceholder.typicode.com/todos/1' | jq -r '.title'All lessons in this course
- Filtering and Selecting JSON with jq Pipelines
- Transforming and Building JSON Objects with jq
- Consuming REST APIs with curl and jq Together
- Editing YAML Configuration Files with yq