Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What content type header to use for JSON? "application/json; charset=utf-8 " or "application/json"?

It seems that the JSON default encoding is UTF-8 and Spring MVC returns application/json; charset=utf-8 by default, which is hard to change.

like image 713
Bobo Avatar asked Nov 06 '13 14:11

Bobo


People also ask

What is the correct JSON Content-Type?

JSON has to be correctly interpreted by the browser to be used appropriately. text/plain was typically used for JSON, but according to IANA, the official MIME type for JSON is application/json .

What is the meaning of Content-Type application JSON charset UTF-8?

Content-type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding is somewhat redundant for JSON, since the default (only?) encoding for JSON is UTF-8.

Does JSON use UTF-8?

JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.

What is default encoding for application JSON?

The MIME media type for JSON text is application/json. The default encoding is UTF-8.


1 Answers

According to RFC 4627

JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.

It goes on to describe how the different UTF-* encoding are to be detecting, suggesting that no other encodings are supported.

"SHALL" represents an absolute requirement here (see RFC 2119).

And there really is no reason to use a non-UTF encoding with JSON (as anything that can handle JSON can definitely handle UTF-8).

like image 171
Joachim Sauer Avatar answered Oct 10 '22 12:10

Joachim Sauer