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

18 Replies, 1436 Views

Dude, I feel you. I wasted hours on this until I found `jq` to format my JSON before posting it with curl.

Try this:
```bash
echo '{"key":"value"}' | jq -c . | curl -H "Content-Type: application/json" -d @- http://example.com/api
```

`jq` ensures your JSON is valid, and `-d @-` reads from stdin. Lifesaver for messy JSON.

Messages In This Thread



Users browsing this thread: 1 Guest(s)