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

18 Replies, 1483 Views

For quick testing, I use Postman or Insomnia to craft the request first, then copy the curl command.

But if you’re stuck with post json curl, try this:

```bash
curl -H "Content-Type: application/json" -d "$(jq -c . <<< '{"key":"value"}')" http://example.com/api
```

`jq` validates the JSON, and `<<<` avoids file clutter.

Messages In This Thread



Users browsing this thread: 1 Guest(s)