Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between JSON content types

I know there exists a question The right JSON content type? but I am confused when should one use which content type.

Hence the question : What are the differences between the various JSON content types and when should one prefer using which one ?

According to answers on similar questions on stackoverflow , application/json is the correct JSON content type but I was thinking then why are the JSON content types still used , what is the reason for that?

like image 912
Rndm Avatar asked Jul 15 '12 06:07

Rndm


People also ask

What is Content-Type for JSON?

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 difference between application JSON and text JSON?

In other words: text if it is readable text (which JSON is) application if its unreadable binary data (which JSON is not)

What is header (' Content-Type application JSON ')?

The function header("Content-type:application/json") sends the http json header to the browser to inform it what kind of data it expects.


2 Answers

You should always use application/json. If whoever you're sending the JSON to expects something else, they're doing it wrong.

That being said, if you really need to communicate with someone who's doing it wrong, obviously you'll have to play by their rules - whatever those may be.

like image 167
Ethan Holshouser Avatar answered Sep 23 '22 17:09

Ethan Holshouser


@Rndm, I'm glad you raised the issue again. It caused me to review and reaffirm it for myself. Thank you.

Not to beat a dead horse, again. But there seems to be precious little consensus on the net about what should be used as the JSON MIME type.

The spec lists clearly only one MIME media type for JSON and it is "application/json" (see https://www.rfc-editor.org/rfc/rfc4627, section "6. IANA Considerations".

However, there seems to be many cases where browsers are expecting other types, and this is unfortunate (see "Having just had a long fight with IE8 myself with this I found that if you're loading the json into an iframe as text/plain", What problems may using the MIME type application/json cause?, Norgg Nov 27 at 16:20).

like image 28
Robert Avatar answered Sep 20 '22 17:09

Robert