0PricingLogin
Linux Command Line & Bash Scripting Mastery · Lesson

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.
  • -r on 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

  1. Filtering and Selecting JSON with jq Pipelines
  2. Transforming and Building JSON Objects with jq
  3. Consuming REST APIs with curl and jq Together
  4. Editing YAML Configuration Files with yq
← Back to Linux Command Line & Bash Scripting Mastery