     [Blog](https://scrapfly.io/blog)   /  [curl](https://scrapfly.io/blog/tag/curl)   /  [Guide to using JSON with cURL](https://scrapfly.io/blog/posts/how-to-curl-json)   # Guide to using JSON with cURL

 by [Ziad Shamndy](https://scrapfly.io/blog/author/ziad) Apr 18, 2026 10 min read [\#curl](https://scrapfly.io/blog/tag/curl) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json "Share on LinkedIn")    

 

 

   

[How to Use cURL For Web Scraping](https://scrapfly.io/blog/posts/how-to-use-curl-for-web-scraping) is a powerful command-line tool used for making HTTP requests, commonly used for sending and receiving JSON data in APIs. Whether you're working with REST APIs, automation scripts, or debugging requests, understanding how to send JSON data with `cURL` is essential.

This guide walks you through various ways to work with `cURL` and JSON, including how to `post JSON`, send a `JSON body`, and even upload a `JSON file` with cURL.

## Key Takeaways

Master cURL JSON handling with multiple input methods, proper headers, and advanced processing techniques for reliable API interactions and data transfer.

- Use cURL post JSON with multiple input methods - files using @filename, inline strings, environment variables, and jq processing
- Always set Content-Type header with -H "Content-Type: application/json" to ensure proper JSON handling
- Implement file-based approach for complex data using @data.json for large payloads and reusable JSON structures
- Configure environment variables for security by storing sensitive data in env vars and referencing with $VAR\_NAME syntax
- Apply jq integration for advanced processing to filter, transform, and validate JSON before sending with cURL
- Use real-world API examples like Slack webhooks and Google Translate to demonstrate production-ready patterns
- Implement error handling and validation by always validating JSON syntax and handling API responses appropriately

**Get web scraping tips in your inbox**Trusted by 100K+ developers and 30K+ enterprises. Unsubscribe anytime.







## Sending JSON from a File

When you're dealing with structured data, it's often more convenient to save your JSON in a file and send it directly. With cURL, you can do this easily using the @ symbol followed by the filename. This is especially useful for larger payloads or cases where you need to reuse the data in multiple requests.

bash```bash
$ curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d @data.json
```



Let's break down the cURL command options:

- `-X POST`: Specifies the HTTP method (POST in this case)
- `-H "Content-Type: application/json"`: Sets the HTTP header indicating that sent data is of JSON type
- `-d @data.json`: Specifies the data to send where `@` tells curl to read the data from a local file instead of a direct string

In the above command, `data.json` is the file containing the JSON payload. `cURL` reads the file and sends its contents as the request body. This method is useful for sending large or complex JSON structures without embedding them directly in the command.

Using `cURL` to post a JSON file keeps your request clean and manageable, making it a great approach for automation scripts and API testing.

Now that we’ve covered sending JSON from a file, let's explore how to send it directly from a string.

## Sending JSON from a String

For quick API requests, you can send JSON directly as a string using the `-d` flag. This method is perfect for smaller payloads or when you’re just testing an API.

bash```bash
$ curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d '{"name": "Alice", "age": 30}'
```



Here, we specify the JSON data inline within the `-d` option. This method works well for quick API requests but can become cumbersome with longer JSON structures.

This inline approach makes it easy to `post JSON` with `cURL` without needing a separate file, which is handy for debugging and quick interactions with APIs.

Sometimes, JSON is generated dynamically from other commands. Let’s see how that works next.

## Sending JSON from Pipe

Piping JSON between commands is a powerful way to dynamically generate, transform, and send data. Here are comprehensive examples demonstrating different piping scenarios:

bash```bash
# Generate JSON with jq and pipe directly to curl
$ echo '{"users": [{"name": "Alice"}, {"name": "Bob"}]}' | jq '.users[0]' | curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d @-
```



The key points here:

- `echo` creates initial JSON
- `jq` filters or transforms the JSON
- `curl -d @-` reads data from stdin (the pipe)

## Sending JSON from Inline Command

Generating JSON dynamically is useful in scripting and automation. A common tool for this is `jq`, which formats JSON output.

bash```bash
$ curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d "$(jq -n --arg name "Alice" --argjson age 30 '{name: $name, age: $age}')"
```



Here’s what happens in the command above:

- `jq -n` starts a new JSON object.
- `--arg` and `--argjson` insert variables into the JSON.
- The output of `jq` is used as the `-d` parameter for `cURL`.

This approach is useful when dynamically constructing JSON from scripts or fetching data from other sources.

Now, let’s see how to use environment variables in JSON payloads.

## Using Environment Variables in JSON

Using environment variables helps make commands more dynamic and reusable. Here's an example:

bash```bash
$ NAME="Alice"
$ AGE=30
$ curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d "{\"name\": \"$NAME\", \"age\": $AGE}"
```



In this example `$NAME` and `$AGE` are substituted with their values and JSON is passed as a string with embedded variables.

This method is particularly useful in scripts where values change dynamically.

Before sending JSON, it's a good idea to validate it. Let's discuss that next.

## Tip: Validate JSON Before Sending

To ensure your JSON is correctly formatted before sending, you can use `jq` or `cURL` with `httpbin.dev` for validation:

bash```bash
$ cat data.json | jq empty
```



If the JSON is invalid, `jq` will return an error. Alternatively, test the JSON by making a POST request to `https://httpbin.dev/post`, which echoes the received data:

bash```bash
$ curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d @data.json
```



You can chain validation and sending in a single command:

bash```bash
# Validate JSON and send only if valid
$ jq empty data.json && curl -X POST https://httpbin.dev/post \
     -H "Content-Type: application/json" \
     -d @data.json
```



Validating JSON beforehand helps avoid errors when interacting with APIs.

Now that we've covered validation, let's look at some real-world examples.

## Real-Life cURL JSON Examples

Here are practical examples of using cURL with JSON for Google Translate and Slack APIs, showing the correct request format for each service.

### Sending JSON to Google Translate API

[Google Translate API](https://cloud.google.com/translate/docs/reference/rest/v2/translate) allows sending JSON to translate text between languages but it requires an api key to use, let's see how we can get it:

1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project
3. Enable the Translate API
4. Create credentials (API key)
5. Restrict the API key to prevent unauthorized use

After aquiring the api key we can now try the api using `cURL`

bash```bash
$ curl -X POST "https://translation.googleapis.com/language/translate/v2?key=YOUR_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
       "q": "Hello, how are you?",
       "source": "en",
       "target": "es",
       "format": "text"
     }'
```



This request translates `"Hello, how are you?"` from English to Spanish.

Next, let’s see how to send JSON messages to Slack.

### Sending JSON to Slack Messages

[Slack](https://slack.com/) provides multiple methods to programmatically send messages to channels and users. The two most common approaches are through the Web API using authentication tokens and through Incoming Webhooks.

#### Sending a Message with API Token

The API approach offers more flexibility with advanced formatting options like blocks, attachments, and interactive elements.

1. Go to [Slack API Dashboard](https://api.slack.com/apps)
2. Create a new app or select an existing one
3. Go to "OAuth &amp; Permissions"
4. Add necessary scopes (e.g., `chat:write`)
5. Install the app to your workspace
6. Copy the "Bot User OAuth Token"

bash```bash
# Example with scopes for posting messages
$ curl -X POST https://slack.com/api/chat.postMessage \
     -H "Authorization: Bearer xoxb-your-bot-token" \
     -H "Content-Type: application/json" \
     -d '{
       "channel": "#alerts",
       "text": "🚨 Server is down! Immediate action required."
     }'
```



#### Using Slack Webhooks

Webhooks provide a simpler implementation for basic messaging needs without requiring OAuth token management.

1. Go to [Slack Incoming Webhooks](https://api.slack.com/messaging/webhooks)
2. Choose a channel
3. Click "Add Configuration"
4. Copy the Webhook URL

bash```bash
$ curl -X POST https://hooks.slack.com/services/YOUR/SPECIFIC/WEBHOOK \
     -H "Content-Type: application/json" \
     -d '{
       "text": "Server down! Urgent action required."
     }'
```



Slack allows sending messages via both API tokens and webhooks. Refer to [Slack’s documentation](https://api.slack.com/messaging/webhooks) for additional details.

## Power Up with Scrapfly



Here's an example of how to POST JSON data to the [Scrapfly Python SDK](https://scrapfly.io/docs/sdk/python):

python```python

from scrapfly import ScrapflyClient, ScrapeConfig, ScrapeApiResponse

scrapfly = ScrapflyClient(key="YOUR SCRAPFLY KEY")
api_response: ScrapeApiResponse = scrapfly.scrape(ScrapeConfig(
     url="https://httpbin.dev/post",
     method="POST"
     headers={"content-type": "application/json"},
     data={"name": "Alice", "age": 30},
     # enable autmatic bot bypass
     asp=True,
     # enable headless browsers?
     # render_js=True
     # customize your proxies?
     country="US",
     proxy_pool="public_residential_pool"
     # and many more features!
))
print(api_response.scrape_result)
```



## cURL Alternatives

cURL is a powerful command-line tool for making HTTP requests, but it’s not always the most user-friendly option. Several alternatives offer better usability or additional features. Here are some top options to consider.

### Curlie

[Sending HTTP Requests With Curlie: A better cURL](https://scrapfly.io/blog/posts/sending-http-requests-with-curlie-a-better-curl) offers cURL’s power with ease of use. It supports both command styles and provides improved default settings for a better developer experience.

**Pros:**

- Enhanced readability with formatted output
- Works with both cURL and HTTPie syntax
- Useful for quick API testing

**Cons:**

- Slight learning curve for cURL users
- Not as feature-rich as raw cURL for advanced cases

For more details read our article:

[Sending HTTP Requests With Curlie: A better cURLIn this guide, we'll explore Curlie, a better cURL version. We'll start by defining what Curlie is and how it compares to cURL. We'll also go over a step-by-step guide on using and configuring Curlie to send HTTP requests.](https://scrapfly.io/blog/posts/sending-http-requests-with-curlie-a-better-curl)

### Postman

[Using API Clients For Web Scraping: Postman](https://scrapfly.io/blog/posts/using-api-clients-for-web-scraping-postman) is a GUI-based API testing tool that simplifies complex API interactions. It provides a visual request builder, variable management, and automation features, making it ideal for developers working with APIs.

**Pros:**

- User-friendly interface
- Excellent for managing API workflows
- Supports automated API testing

**Cons:**

- Higher system resource usage
- Not suitable for quick terminal-based requests

For more details read our article:

[Using API Clients For Web Scraping: PostmanIn this article, we'll explore the use of API clients for web scraping. We'll start by explaining how to locate hidden API requests on websites. Then, we'll explore importing, manipulating, and exporting them using Postman to develop efficient API-based web scrapers.](https://scrapfly.io/blog/posts/using-api-clients-for-web-scraping-postman)

### Curl Impersonate

[Curl Impersonate](https://scrapfly.io/blog/posts/curl-impersonate-scrape-chrome-firefox-tls-http2-fingerprint) is a modified version of cURL designed for web scraping and bypassing anti-bot protections. It mimics browsers like Chrome and Firefox, helping requests appear more legitimate.

**Pros:**

- Reduces chances of detection when scraping websites
- Supports browser-like TLS and HTTP2 fingerprinting

**Cons:**

- Requires additional setup
- Not necessary for general use cases

For more details read our article:

[Use Curl Impersonate to scrape as Chrome or FirefoxLearn how to prevent TLS fingerprinting by impersonating normal web browser configurations. We'll start by explaining what the Curl Impersonate is, how it works, how to install and use it. Finally, we'll explore using it with Python to avoid web scraping blocking.](https://scrapfly.io/blog/posts/curl-impersonate-scrape-chrome-firefox-tls-http2-fingerprint)

Each tool has unique strengths, so the best choice depends on your needs. If you prefer a GUI, Postman might be best. For command-line work, Curlie, or Curl Impersonate are solid choices.



## FAQ

How do I send JSON with cURL?You can send JSON using the -d option with -H "Content-Type: application/json", either from a file (@data.json) or inline ('{"key": "value"}').







Can I send JSON with a GET request in cURL?No, GET requests typically do not support a request body. However, some APIs may allow it, though it is not standard practice and not valid as per the HTTP protocol.







How do I validate JSON before sending it?You can use jq empty to check if the JSON is well-formed, or send a test request to <https://httpbin.dev/post> to confirm its structure.









## Summary

In this guide, we covered various ways to send JSON using `cURL`:

- Sending JSON from a **file** or **inline string** using the `-d` option.
- Setting and using **environment variables** for dynamic values in curl requests.
- Generating JSON with **jq** before sending it off.
- Using JQ to **validate JSON** before sending it.
- Real-world curl JSON post examplers like **Google Translate API** and **Slack messages**.

With these techniques, you can confidently send JSON data using `cURL` in any API workflow.



 

    Table of Contents- [Key Takeaways](#key-takeaways)
- [Sending JSON from a File](#sending-json-from-a-file)
- [Sending JSON from a String](#sending-json-from-a-string)
- [Sending JSON from Pipe](#sending-json-from-pipe)
- [Sending JSON from Inline Command](#sending-json-from-inline-command)
- [Using Environment Variables in JSON](#using-environment-variables-in-json)
- [Tip: Validate JSON Before Sending](#tip-validate-json-before-sending)
- [Real-Life cURL JSON Examples](#real-life-curl-json-examples)
- [Sending JSON to Google Translate API](#sending-json-to-google-translate-api)
- [Sending JSON to Slack Messages](#sending-json-to-slack-messages)
- [Power Up with Scrapfly](#power-up-with-scrapfly)
- [cURL Alternatives](#curl-alternatives)
- [Curlie](#curlie)
- [Postman](#postman)
- [Curl Impersonate](#curl-impersonate)
- [FAQ](#faq)
- [Summary](#summary)
 
    Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fposts%2Fhow-to-curl-json) 



 ## Related Articles

 [  

 python playwright 

### How to Scrape Google Maps

We'll take a look at to find businesses through Google Maps search system and how to scrape their details using either S...

 

 ](https://scrapfly.io/blog/posts/how-to-scrape-google-maps) [  

 python scrapeguide 

### How to Scrape Google Search Results in 2026

In this scrape guide we'll be taking a look at how to scrape Google Search - the biggest index of public web. We'll cov...

 

 ](https://scrapfly.io/blog/posts/how-to-scrape-google) [  

 python seo 

### How to Scrape Google Trends using Python

In this article we'll be taking a look at scraping Google Trends - what it is and how to scrape it? For this example, we...

 

 ](https://scrapfly.io/blog/posts/how-to-scrape-google-trends) 

  ## Related Questions

- [ Q How to load local files in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-load-local-files-in-puppeteer)
- [ Q How To Send cURL POST Requests? ](https://scrapfly.io/blog/answers/how-to-send-a-post-request-using-curl)
- [ Q How To Download a File With cURL? ](https://scrapfly.io/blog/answers/how-to-download-file-curl)
- [ Q How to Send a HEAD Request With cURL? ](https://scrapfly.io/blog/answers/how-to-send-curl-head-requests)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)