application/json
application/json is the type for JSON text (RFC 8259). JSON exchanged between systems must be UTF-8, so the type defines no charset parameter: application/json; charset=utf-8 is common and harmless, but adds nothing.
Open in cURL Builder A request with this type is filled in.
Header
Content-Type: application/jsonAt a glance
- Extensions
- .json
- Kind
- Text
- Parameters
- None
- In a browser
- Shows the text; Firefox shows a collapsible tree. A script reads it with
response.json().
With curl
curl https://api.example.com/users \
-H 'Content-Type: application/json' \
-d '{"name":"Ada","lang":"en"}'With fetch
await fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Ada', lang: 'en' })
});Common mistakes
Forgetting the header
curl
-dlabels the bodyapplication/x-www-form-urlencoded, and JSON middleware such as Express'sexpress.json()then leaves it unparsed. Send the header, or usecurl --json, which sets it andAccepttoo.fetchdoes not stringifyAn object passed as
bodygoes out as the text[object Object]. CallJSON.stringify, and set the header yourself:fetchlabels a string bodytext/plain;charset=UTF-8.Large numbers lose precision
In JavaScript,
JSON.parserounds integers above 2^53 (9007199254740993becomes9007199254740992). Send big ids as strings.