Developer Toolbox

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/json

At 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 -d labels the body application/x-www-form-urlencoded, and JSON middleware such as Express's express.json() then leaves it unparsed. Send the header, or use curl --json, which sets it and Accept too.

  • fetch does not stringify

    An object passed as body goes out as the text [object Object]. Call JSON.stringify, and set the header yourself: fetch labels a string body text/plain;charset=UTF-8.

  • Large numbers lose precision

    In JavaScript, JSON.parse rounds integers above 2^53 (9007199254740993 becomes 9007199254740992). Send big ids as strings.