# Send JSON with cURL in Java

Paste a curl command that sends JSON and get idiomatic Java code. We pick the right serialization for OkHttp and set the correct Content-Type.

## Example

```bash
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada","email":"ada@example.com"}'
```

## What the converter handles

- Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
- JSON bodies are parsed and re-emitted through OkHttp's serializer so quoting stays consistent with what the server expects.
- Charset directives on Content-Type (e.g. application/json; charset=utf-8) survive the round trip.

## Common mistakes

- Setting Content-Type manually and then also using OkHttp's helper — you end up with duplicate headers or the wrong one wins.
- Mixing form encoding with JSON headers — the server rejects with 400 and it's easy to miss in code review.
- Trusting the browser DevTools "Copy as cURL" to preserve charset — it often drops it. Clean panel restores common defaults.

## FAQ

### How is JSON encoded in the generated Java?

Toolpaper detects Content-Type: application/json and emits idiomatic OkHttp JSON serialization (json= for requests, Response.json for Go, etc.).

### Does it preserve Content-Type?

Yes. The Content-Type header is honored and matched against the body so serialization stays consistent.

### Is anything uploaded?

No. Parsing and generation happen entirely in your browser.

---

Source: https://toolpaper.manavdev.site/how-to/send-json-with-curl-in-java · Language hub: https://toolpaper.manavdev.site/curl-to-java