Content-Type for JSON API with UTF-8
Learn how to set the Content-Type header for a standard JSON API request with UTF-8 charset. Covers application/json usage and when charset is needed.
Detailed Explanation
application/json; charset=utf-8
The most common Content-Type for modern REST APIs is application/json. When you include charset=utf-8, you explicitly declare that the JSON payload is encoded in UTF-8.
The Header Value
Content-Type: application/json; charset=utf-8
Why UTF-8?
RFC 8259 (the JSON specification) states that JSON text exchanged between systems that are not part of a closed ecosystem must be encoded in UTF-8. While most JSON libraries default to UTF-8, adding the charset parameter makes the encoding explicit and avoids ambiguity when working with proxies, gateways, or legacy systems.
When to Omit charset
If both client and server are modern and JSON-only, you can often send just application/json without the charset parameter. The specification considers UTF-8 the default. However, including it is harmless and can prevent subtle bugs when intermediaries inspect or transform the payload.
Output Formats
Raw header:
Content-Type: application/json; charset=utf-8
curl:
curl -H "Content-Type: application/json; charset=utf-8" -d '{"key":"value"}' https://api.example.com
fetch():
fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify({ key: "value" })
});
Use Case
Use this when sending JSON payloads to REST APIs, webhook endpoints, or any backend service that expects JSON. This is the go-to Content-Type for nearly all modern web API integrations.