How to Properly POST JSON Data Using cURL? or What’s the Correct Way to POST JSON with cURL?

18 Replies, 1435 Views

Ah, the classic post json curl struggle! Your command looks mostly correct, but yeah, escaping quotes can be a pain. If your JSON has nested quotes, try wrapping the whole thing in single quotes and escaping the inner doubles with a backslash, like this:

```bash
curl -H "Content-Type: application/json" -d '{\"key\":\"value with \\\"quotes\\\" inside\"}' http://example.com/api
```

And nah, you don’t *need* `-X POST` if you’re using `-d`, since curl defaults to POST with data. But it doesn’t hurt to be explicit.

Messages In This Thread



Users browsing this thread: 1 Guest(s)