by Stian

Correct content type for JSON

When I Google around searching for any code snippets I might need for inspiration (or plain copy-paste), I see a lot of different use of MIME type for JSON in examples and existing code out there.

Examples of types found with a quick JSON google search:


You could of course argue that the reason for this is that the browsers do have a bit of history when it comes to supporting “standards”, but there is only one correct media type for JSON:

Content-Type: application/json

You can find this registered at IANA (Internet Assigned Numbers Authority), take a look here.

What about JSONP?

Since we are on the subject, you might also be wondering what the correct content type for JSONP is, because this is different. JSONP returns JavaScript and the correct usage would be

Content-Type: application/javascript

If you find this useful or in any way disagree, holla at me!