0

What's the difference between application and text in media types and when do they use what?

For example there is text/html but on the other hand it's application/json.

Is this a historical thing?

Piu130
  • 1,288
  • 3
  • 16
  • 28

1 Answers1

3

This is described on the MIME types page of the mozilla documentation.

application refers to any kind of binary data while text is theoretically human readable.

type/subtype

The structure of a MIME type is very simple; it consists of a type and a subtype, two strings, separated by a '/'. No space is allowed. The type represents the category and can be a discrete or a multipart type. The subtype is specific to each type.

A MIME type is case-insensitive but traditionally is written all in lower case.

Further down the page you can find a table containing the discrete types:

Type          Description
text          Represents any document that contains text and is theoretically human readable
image         Represents any kind of images. Videos are not included, though animated images (like animated gif) are described with an image type.
audio         Represents any kind of audio files
video         Represents any kind of video files
application   Represents any kind of binary data.

To answer your question about JSON, while you'll frequently come across JSON that is human readable it's primarily used for containing data and isn't necessarily intended to simply be read. Meanwhile a machine can always easily convert the data from JSON into an object (assuming the JSON is correctly formatted).

Nick is tired
  • 6,860
  • 20
  • 39
  • 51
  • Can you make an example? Because `

    hello

    ` is not more readable than `{"data": "hello"}` or `{"binary": "njkdfFGG"}` and HTML is also (always) converted to an Object?
    – Piu130 Jul 05 '18 at 13:04
  • @Piu130 It doesn't make sense to make an example, HTML and JSON aren't (necessarily) interchangable, `

    hello

    ` is not equivalent to `{"data": "hello"}`. Of course you can create an example where HTML is less readable than JSON, but in the real world it's less likely, after all HTML is often hand written, while JSON is more frequently generated
    – Nick is tired Jul 05 '18 at 13:24
  • @Piu130 In other words, if you were creating a website from scratch, would you rather write HTML or JSON? ;), consider the examples [here](https://stackoverflow.com/questions/2303713/how-to-serialize-dom-node-to-json-even-if-there-are-circular-references) – Nick is tired Jul 05 '18 at 13:28