Tool cheatsheet
curl and jq 8 Cheatsheet
Make HTTP requests with curl and slice JSON responses with jq, from the command line.
Making requests
- Make a GET request — Fetch a URL and print the response body.
- Hide the progress meter — Suppress progress output but still show errors, which suits scripts.
- Fetch only the headers — Send a HEAD request and print the response headers.
- Follow redirects — Follow Location headers until the final response.
- POST JSON — Send a JSON body with the correct content type.
- POST a JSON file — Send the contents of a file as the request body.
- Use other HTTP methods — Choose the method with -X, here DELETE.
- Submit a form — Send URL-encoded form fields.
- URL-encode a value — Send a value that needs encoding, as a query string for a GET request.
Authentication and headers
- Send a bearer token — Authenticate with a token from an environment variable.
- Use basic authentication — Send a username, with curl prompting for the password.
- Set a header — Send any request header you need.
- Set the User-Agent — Send a custom User-Agent header.
- Save and send cookies — Store cookies in a file and send them on later requests.
Files and output
- Save to a file — Write the response body to a file.
- Save with the remote file name — Use the file name from the URL.
- Resume a download — Continue a partial download where it stopped.
- Upload a file — Upload a file as multipart form data.
- Print only the status code — Discard the body and print the HTTP status.
- Measure response time — Print how long the request took in seconds.
Debugging and reliability
- See the whole exchange — Print the request and response headers and TLS details.
- Fail on HTTP errors — Return a non-zero exit code on 4xx and 5xx responses, and print the body.
- Retry on failure — Retry up to five times on transient errors.
- Set a timeout — Give up if the whole operation takes longer than 10 seconds.
- Skip TLS certificate checks — Allow connections to servers with invalid certificates. Use it only to debug.
- Test a host before DNS changes — Send a request to a specific IP address while keeping the host name.
jq: filter and transform JSON
- Pretty-print JSON — Format JSON with indentation and colors.
- Get a field — Extract one field from an object.
- Get a field without quotes — Output raw strings instead of JSON strings, handy in scripts.
- Iterate over an array — Output each element of an array.
- Get a field from each element — Output the name of every user.
- Filter elements — Keep users older than 30.
- Count elements — Count the items in an array.
- List an object's keys — Output the keys of an object.
- Output compact JSON — Print each result on one line, which suits line-oriented tools.
- Build a new object — Create objects with only the fields you want.
- Sort by a field — Sort an array of objects by a field.
- Group by a field — Group array elements that share a value.
- Convert to CSV — Turn arrays of values into CSV rows.
- Pass a shell variable — Use a shell value inside a jq filter without quoting problems.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.