In this article, we look at the correct mime types for JSON and JSONP as defined in the official IANA media types list.

Media Type Mime-type RFC
JSON application/json RFC 4627
JSONP application/javascript RFC 4392

#JSON Mime Type

RFC 4627 specifies that the correct mime-type for JSON is:

application/json
  • If you wish to support IE7 (or below), using application/json might not work as expected because Internet Explorer will associate application/json to an application installed on the client-side and will show a "Save As" disalog box. In that case, the solution might be to use the mime-type text/javascript instead.
  • As a precaution, you should avoid serving json with the content-type text/html as it can be a potential security risk.

#JSONP Mime Type

For JSONP the correct mime-type would be the same as it is for JavaScript (as stated in RFC 4392), which is:

application/javascript

It is so because the response body of a JSONP response is essentially JavaScript.

#Variants in the Wild:

Be aware of variants in the wild, which are either obsolete or non-standard and are discouraged for use. Some notable examples are:

text/javascript
text/ecmascript
text/jscript
text/livescript
text/x-javascript
text/x-ecmascript
application/x-javascript
application/x-ecmascript
application/javascript
application/ecmascript

Serving media with an incorrect mime-type can potentially lead to unwanted behavior and/or security risks.

Published (last revised ) by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing.