7

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?

Community
  • 1
  • 1
Rndm
  • 6,270
  • 7
  • 36
  • 58
  • possible duplicate of [What problems may using the MIME type application/json cause?](http://stackoverflow.com/questions/4792291/what-problems-may-using-the-mime-type-application-json-cause) – user123444555621 Jul 15 '12 at 11:25
  • 1
    I explained the issue I faced and have also pointed out that my main aim is rather to find out the differences between the various JSON content types , then why a duplicate ? – Rndm Jul 15 '12 at 12:34
  • 1
    In that case I guess the problem is understanding the general concept of content types, and has little to do with JSON. You may want to rephrase the question. – user123444555621 Jul 15 '12 at 17:00

2 Answers2

3

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.

Ethan Holshouser
  • 1,392
  • 15
  • 13
  • 1
    In the client js code(which I wrote) , I expect to recieve a JSON , I tried checking the data I received using alerts and found the issue I mentioned , hence changed the content type, and then it worked fine. – Rndm Jul 15 '12 at 06:40
  • This probably isn't what you want to hear, but `application/json` is _the_ content type for JSON. If your client isn't accepting `application/json` then there is something wrong with your javascript code. Perhaps you should post it here and someone can help you find the problem. You would probably want to do that in a separate question, though. – Ethan Holshouser Jul 15 '12 at 06:48
  • Ok , will do that , I also wanted to find out the difference between the various content types after that , any pointers on that ? – Rndm Jul 15 '12 at 06:50
  • If you're talking about JSON content types, the only real difference is that `application/json` is correct and the others are not. – Ethan Holshouser Jul 15 '12 at 06:53
  • 1
    If you're not only talking about JSON, you can find more information here: http://www.utoronto.ca/web/htmldocs/book/book-3ed/appb/mimetype.html – Rob Angelier Jul 20 '12 at 06:01
2

@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 http://tools.ietf.org/html/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).

Robert
  • 522
  • 6
  • 15