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:

application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json

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!

  • http://blog.degree.no/bloggere/ Andreas

    Also be aware of the way different browsers handle JSON responses. IE has a bad habit of initiating the “download file” dialog, as described in one of our other blog posts