What is the correct JSON content type?

I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly.

I have seen so many purported "standards" for the JSON content type:

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

But which is correct, or best? I gather that there are security and browser support issues varying between them.

I know there's a similar question, What MIME type if JSON is being returned by a REST API?, but I'd like a slightly more targeted answer.


For JSON text:

The MIME media type for JSON text is application/json . The default encoding is UTF-8. (Source: RFC 4627).

For JSONP with callback:

application/javascript

Here are some blog posts that were mentioned in the comments that are relevant.

  • Why you shouldn't use text/html for JSON
  • Internet Explorer sometimes has issues with application/json
  • A rather complete list of Mimetypes and what to use them for

  • IANA has registered the official MIME Type for JSON as application/json .

    When asked about why not text/json , Crockford seems to have said JSON is not really JavaScript nor text and also IANA was more likely to hand out application/* than text/* .

    More resources:

  • Media Types
  • Request for Comments 4627
  • bluesmoon: JSON has a type

  • For JSON:

    Content-Type: application/json
    

    For JSON-P:

    Content-Type: application/javascript
    
    链接地址: http://www.djcxy.com/p/10.html

    上一篇: 如何修改现有的,未完成的提交?

    下一篇: 什么是正确的JSON内容类型?