Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To request a JSON representation with cURL, send an HTTP request and ask for JSON with an Accept header:
curl -sS -H 'Accept: application/json' 'https://api.example.com/resource'
The endpoint still decides what it returns. Its documentation defines the URL, authentication, query parameters, content-negotiation behavior, and response schema. For a JSON request body, use --json on curl 7.82.0 or newer, or the explicit Content-Type and --data-binary form on older versions.
Get JSON from an API with cURL
A GET request normally retrieves an API representation. The following command suppresses the progress meter while preserving diagnostics for failures:
curl -sS -H 'Accept: application/json' 'https://api.example.com/resource'
-sSor--silent --show-errorhides normal transfer progress but still prints errors.-Hor--headeradds theAccept: application/jsonrequest header.- The quoted URL prevents the shell from interpreting characters such as
&and?.
An Accept header is a request, not a guarantee. Some APIs always return JSON; others select a representation only when the header is supported; an endpoint may return HTML for an error or redirect. Check the API documentation and the response headers before assuming the body is JSON.
#1 Best Overall
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Add authentication and query parameters
Use the authentication method documented by the API. A bearer-token example is:
curl -sS
-H 'Accept: application/json'
-H "Authorization: Bearer $API_TOKEN"
--get 'https://api.example.com/resource'
--data-urlencode 'status=active'
--data-urlencode 'limit=20'
--get keeps the parameters in the query string. --data-urlencode safely encodes spaces, ampersands, and other special characters. Do not put secrets directly in shell history when an environment variable or a credential mechanism supported by the API is available.
Format or select fields with jq
cURL writes the response bytes to standard output. jq is optional, but it makes JSON readable and can select values:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
curl -sS -H 'Accept: application/json' 'https://api.example.com/resource' | jq .
For an array under data, print each item’s name:
curl -sS 'https://api.example.com/resource' | jq -r '.data[].name'
jq . pretty-prints without changing the data model. The -r option emits raw strings without JSON quotes, which is useful in shell pipelines. If the server returns invalid JSON, jq reports a parse error; inspect the unfiltered response and HTTP headers before changing the filter.
POST JSON with modern cURL
curl 7.82.0 introduced --json. It is a shortcut for sending the body with --data-binary, setting Content-Type: application/json, and asking for a JSON response with Accept: application/json:
curl --json '{"name":"Ada","active":true}'
'https://api.example.com/endpoint'
The option can be used more than once. It accepts inline data, a file, or standard input:
Rank #2
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
curl --json @payload.json 'https://api.example.com/endpoint'
curl --json @- 'https://api.example.com/endpoint' < payload.json
Use a file for a sizeable or reusable payload. Keep shell quoting in mind: single quotes preserve JSON double quotes on POSIX shells, while PowerShell uses different quoting rules.
Free tools Windows power users keep installed
One-click scans. No signup required.
POST with authentication and an explicit method
curl -sS --json @payload.json
-H "Authorization: Bearer $API_TOKEN"
'https://api.example.com/endpoint'
Most APIs infer POST when a request body is supplied. If the API requires another method, follow its documentation; do not assume that adding a body alone changes the intended operation.
POST JSON on older cURL versions
Before 7.82.0, write the headers and body options explicitly:
curl -sS -X POST
-H 'Content-Type: application/json'
-H 'Accept: application/json'
--data-binary @payload.json
'https://api.example.com/endpoint'
For a small inline body:
curl -sS -X POST
-H 'Content-Type: application/json'
-H 'Accept: application/json'
--data-binary '{"name":"Ada","active":true}'
'https://api.example.com/endpoint'
--data-binary sends the bytes as provided, including line endings. Unlike --data, it does not strip carriage returns or newlines. That distinction matters for signatures and exact payloads.
Choose an input method
| Approach | Minimum/version note | Best use | Trade-off |
|---|---|---|---|
--json '…' |
curl 7.82.0 or newer | Short JSON requests with conventional JSON headers | Less explicit control; it does not validate syntax |
--json @file or --json @- |
curl 7.82.0 or newer | Reusable files and piped input | Requires managing the input file or pipeline |
--data-binary @file plus headers |
Works with older versions | Precise byte handling and maximum header control | More verbose |
Pipe to jq |
Separate jq installation | Pretty output or field extraction | Transforms display output; it is not part of the HTTP request |
Check your version with curl --version. The --json shortcut was added in curl 7.82.0, documented by the curl project in 2022.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsValidate JSON before sending it
cURL does not parse or validate the value passed to --json. The curl documentation explicitly warns that there is no verification that the supplied data is actual JSON or syntactically correct. A malformed body is transmitted and the server may return a parsing error.
Rank #3
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
When jq is available, validate a file without making a request:
jq empty payload.json
For generated data, produce JSON with a serializer rather than concatenating strings. This avoids unescaped quotes, newlines, and booleans represented as text.
Python example for a JSON POST
import json
import requests
payload = {"name": "Ada", "active": True}
response = requests.post(
"https://api.example.com/endpoint",
json=payload,
headers={"Authorization": "Bearer " + API_TOKEN},
timeout=30,
)
response.raise_for_status()
print(response.json())
The Python client serializes the object and sets the JSON content type. Keep the API’s authentication and schema requirements unchanged when adapting the example.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Node.js example for a JSON POST
const payload = { name: 'Ada', active: true };
const res = await fetch('https://api.example.com/endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${process.env.API_TOKEN}`
},
body: JSON.stringify(payload)
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
Inspect status codes, headers, and error bodies
When a command fails, diagnose the HTTP exchange before changing the JSON:
curl -i -sS -H 'Accept: application/json' 'https://api.example.com/resource'
curl -D headers.txt -sS 'https://api.example.com/resource'
curl -v 'https://api.example.com/resource'
-ior--includeprints response headers before the body.-D headers.txtor--dump-headersaves headers separately.-vor--verboseshows connection, request, and response diagnostics; avoid sharing its output when it contains credentials.
Look for the HTTP status, Content-Type, redirects, authentication challenges, and the server’s error JSON. A 401 or 403 points to credentials or permissions, a 404 to the URL or resource, a 415 to the request content type, and a 422 or 400 commonly indicates a schema or validation problem. These meanings are conventions; the API’s documentation and error body are authoritative.
Common problems and fixes
The output is HTML instead of JSON
Confirm the URL, authentication, and redirect behavior. The response may be a login page, proxy error, or an API error rendered as HTML. Use -i and inspect Content-Type. Add Accept: application/json only when the API documents it; the header cannot make a non-JSON endpoint become JSON.
Rank #4
- 5 in 1 Connectivity: The USB C Multiport Adapter is equipped with a 4K HDMI port, a 100W USB C PD port, a 5 Gbps USB A data port, and two 480 Mbps USB A ports
“Unknown option: –json”
Your curl predates 7.82.0. Use the explicit Content-Type, Accept, and --data-binary command, or upgrade curl through your operating system’s supported package channel.
HTTP 415 Unsupported Media Type
The server did not recognize the request body format. For a JSON POST, send Content-Type: application/json. With older curl, include it manually; with --json, curl supplies it.
HTTP 400, 422, or a JSON parse error
Validate the payload with jq empty, compare property names and types with the API schema, and ensure the endpoint expects the method you used. Remember that --json sends bytes but does not check their syntax.
jq says “parse error”
First save the unfiltered response, then inspect it with curl -i. A gateway error, HTML page, truncated transfer, or an API that returned plain text can all produce this message. Fix the HTTP response or endpoint before changing the jq expression.
Query parameters are missing or corrupted
Quote the URL and use --get --data-urlencode for query values. An unquoted ampersand can make the shell start a background job, and unescaped spaces can split one argument into several.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchAuthentication works in a browser but not cURL
Browser cookies, redirects, CSRF tokens, and interactive login state are not automatically present in cURL. Use the API’s documented token, API key, cookie, or OAuth flow. Never paste a secret into a public script or support log.
Best Value
- Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
- Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
- 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
- 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
- Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.
Reliability, performance, and scripting practices
- Set a timeout appropriate to the API, such as
--max-time 30, so a hung connection does not block a job forever. - Use
--fail-with-bodywhere supported when scripts should treat HTTP errors as failures while retaining the response body for diagnosis. - Write machine-readable output to a file with
-o response.jsonand process it only after checking the command’s exit status. - Do not blindly retry POST requests. A timeout can occur after the server accepted the request; retry only when the API documents idempotency keys or safe retry behavior.
- For repeated calls, respect rate limits and backoff instructions from response headers or API documentation.
- Keep the response’s encoding and exact bytes when signatures, hashes, or downloads matter; use
--data-binaryfor request bodies and avoid unnecessary formatting steps.
What JSON means here
JSON is a text interchange format defined for interoperable data. RFC 8259, published by the RFC Editor and IETF in December 2017, describes its syntax and interoperability considerations. cURL transports the bytes; it does not enforce the full JSON specification or the API’s application-level schema. The server remains responsible for validating required fields, types, and business rules.
Or skip the browser setup
If your actual goal is to capture a website rather than call a JSON API, ScreenshotNeo provides a single screenshot request without setting up a headless browser:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for parameters and response handling. Before capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and whether it was billed. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card, and paid plans start at $5 for 3,000 shots. Sign up for the free plan.
Recommended Free Tools
Frequently Asked Questions
Does cURL automatically return JSON?
No. cURL returns whatever bytes the endpoint sends. Use the documented URL and request headers, then verify the response’s status and Content-Type.
Is jq required to use JSON with cURL?
No. jq only formats or queries the response after cURL receives it.
Can I send a JSON file from standard input?
Yes. On curl 7.82.0 or newer, use –json @- and redirect or pipe the JSON into cURL.
Why did my POST succeed but produce no visible output?
The server may return an empty body, a 204 status, or output that was redirected with -o. Inspect the status and headers with -i or -D.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

