5 ms·
Why do we use html instead of json?
JSON replaced XML for a ton of applications. It's compact and easy to work with. Why hasn't html been replaced by JSON or something analogous?
- informatimago 13y agoThe real question is why do we use html instead of lisp s-exps? I guess the answer is contained in the expletive: "Boo!"
- codeonfire 13y agoThere are the markdown and wiki formats. XML is a mark-up language. Most structured data just doesn't need to be marked up, so XML doesn't always make sense and something like JSON does. Web content is often continuous text that does, indeed, need to be marked up. Occasionally, HTML is used to define a form or something that isn't continuous text. In those cases, the form html can be generated from the underlying data types in whatever language the application is written in or using a domain specific language that resembles JSON but represents HTML.
- gesman 13y agoWith so many HTML junkyards out there - it's a de-facto standard. Same with XML. The moment I saw XML's <tag>...</tag> - I asked - why don't we just use <tag>...</> to save 15% of world's bandwidth? No one was able to answer this question.
- ghostdiver 13y agoHow about gzip compression? It's not like you can gain anything by using JSON compared to HTML, when gzip is enabled.
- mcrider 13y agoWriting something like "<p>This is a statement with <strong>bold text</strong></p>" does not really translate well to JSON.
- cheald 13y agoSure it does. { type: "tag", tag: "p", children: [ {type: "text", content: "This is a statement with "}, {type: "tag", tag: "strong", children: [ {type: "text", content: "bold text"} ]} ] } That also rather explains why we don't use JSON.
- ryanto 13y agoJSON is probably a better format for describing data, but maybe not for document markup. Take the following code snipit: <p class="justify"><strong>hello</strong> world</p> How would you represent this in JSON? Here is my guess. { node: "paragraph", attributes: [{ class: "justify" }], children: [{ node: "strong", content: "hello" },{ node: "text", content: "world" }] } There is a few things to note between these two examples. In the XML version it is much easier to distinguish the actual content from the meta data. Right away we can see the p tag describing the content "hello world" with metadata as class/justify. Also, since webpages are all text (we can view this as there is no data type) JSON may become less valuable. We don't really describe types well in XML, but that shouldn't matter on a webpage since it is only text. Where as in a data serialization format, like JSON, that sort of thing is extremely important. I don't feel strongly about XML, but I don't think I want to use the same format for describing data as I do to describe my documents.
- cheald 13y agoOne reason is that JSON doesn't cleanly map to s-expressions. You can fake it with an arbitrary attribute, but there isn't a 1:1 mapping. The biggest reason is that HTML was designed to mark up human-readable documents, rather than to describe machine-readable documents. You can remove all the markup from a web page and easily read its contents; you can't do the same with JSON.
- cgore 13y ago(html (head (title "Hi there")) (body (h1 "Hi there") (p "S-expressions are " (b "a lot nicer") " than HTML/XML/etc.")))
- cheald 13y agoRight; my point is that XML is fully capable of representing s-expressions, but JSON is not, and much of what we write as HTML is effectively just sexps.