How to properly use curl POST JSON in my API requests? or What's the correct syntax for a curl POST J

14 Replies, 1863 Views

For curl post json, headers are non-negotiable. Also, Windows cmd butchers quotes. Two fixes:

1. Use double quotes *outside*, escape inner ones:
```bash
curl -X POST https://api.example.com/data -H "Content-Type: application/json" -d "{\"name\":\"test\",\"value\":123}"
```

2. Or use `curl --data-binary` to avoid quote chaos:
```bash
curl -X POST https://api.example.com/data -H "Content-Type: application/json" --data-binary "@data.json"
```

Save your JSON to `data.json` first. Lifesaver for Windows users.

Messages In This Thread



Users browsing this thread: 1 Guest(s)