What's the default encoding of HTTP POST request when the content-type is "application/json" with no explicit charset given"?
It seems two specs are in conflicts:
The application/json
media type is formally defined in RFC 7158 The JavaScript Object Notation (JSON) Data Interchange Format
(which obsoletes RFC 4627), and is registered with IANA has having NO required or optional parameters (thus, charset
is not defined for application/json
).
Section 8.1 Character Encoding says:
JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32. The default encoding is UTF-8, and JSON texts that are encoded in UTF-8 are interoperable in the sense that they will be read successfully by the maximum number of implementations; there are many implementations that cannot successfully read texts in other encodings (such as UTF-16 and UTF-32).
Implementations MUST NOT add a byte order mark to the beginning of a JSON text. In the interests of interoperability, implementations that parse JSON texts MAY ignore the presence of a byte order mark rather than treating it as an error.
application/...
media types are typically defined as binary formats. It is very easy for a JSON parser to differentiate between UTF-8, UTF-16, and UTF-32 just by looking at the first few bytes, so there is no need for a BOM (which is not allowed, as noted above) or an explicit charset
(which is not defined).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With