Back to blog

    HTTP requests

    How to send a POST request with JSON using cURL

    To send JSON with curl, use POST, add a Content-Type: application/json header, and pass the JSON payload with -d.

    6 min readUpdated 2026-04-28

    The basic JSON POST command

    Most APIs expect JSON requests to include a Content-Type header. Without it, the server may treat your body as plain text or form data.

    POST JSON
    curl -X POST https://api.example.com/users \
      -H "Content-Type: application/json" \
      -d '{"name":"Ada Lovelace","email":"[email protected]"}'

    What each part does

    -X POST tells curl to use the POST method. -H adds the Content-Type header. -d sends the JSON body.

    Many APIs infer POST when you use -d, but writing -X POST can make examples easier for beginners to read.

    Common mistakes

    The most common mistakes are invalid JSON, missing quotes, missing Content-Type, and shell escaping problems. If your JSON contains quotes, make sure your shell quoting is correct.

    On Windows PowerShell, quoting rules differ from bash, so examples may need small adjustments.

    Converting JSON POST to code

    Once the curl request works, convert it into application code. In Python, the JSON payload usually becomes a dictionary passed to requests.post. In JavaScript, it usually becomes JSON.stringify inside a fetch request.

    Try it with curlcode

    Have a curl command already? Paste it into one of the converters below to generate language-specific HTTP request code.

    Frequently asked questions

    Do I need -X POST when using -d?

    curl usually uses POST automatically when -d is present, but -X POST can make the command explicit.

    Why do I need Content-Type: application/json?

    It tells the server that the request body is JSON.

    Can I send JSON from a file?

    Yes. You can use -d @file.json, depending on the exact curl behavior you need.

    Can I convert a JSON curl POST to code?

    Yes. It maps cleanly to most HTTP clients, including Python requests, JavaScript fetch, and Node Axios.

    Related guides