4 ms·
HTML would be much easier to write if it were based on JSON. Less bandwidth too. Has this been attempted?
by rvkennedy 13y ago
HTML would be much easier to write if it were based on JSON. Less bandwidth too. Has this been attempted?
- TazeTSchnitzel 13y agoAre you kidding me? Currently: <ul> <li>Hello!</li> </ul> By your suggestion: { "tagName": "ul", "children": [ { "tagName": "li", "children": [ "Hello!" ] } ] } (and, yes, it has been attempted... JSON.stringify(document.body))
- talmand 13y agoI don't think your example needs to be quite so verbose. { 'ul': { 'li': 'hello!' } } I would think it would depend upon the parser. Regardless, I'd still rather write out HTML instead of JSON for markup.
- bct 13y agoThat breaks down as soon as you have something with attributes, and it breaks down even further once you have something like: <p>Example <b>text</b></p>
- talmand 13y agoYou see, this is why I don't create standards. I'm going to go with that JSON is the failure point with my grand vision.
- nobleach 13y agoNot sure your example would work in a real world situation. The UL would probably have an array attached as it can have multiple children. Then we get into the fact that all tags can have attributes, not just a text node.
- talmand 13y agoYou're right, I didn't consider attributes. In my simplified way the parser would need to know which keywords were attributes based on parent element versus keywords that are just new children elements. Which would defeat the purpose. I guess I'm not changing the world today.
- bzbarsky 13y ago> JSON.stringify(document.body) One of two things will happen, depending on your browser. If your browser is following the WebIDL spec, so all the accessors are on the prototype, this will produce "{}". If your browser is WebKit-based, this will throw an exception, because body.firstChild.parentNode == body and JSON.stringify throws on object graphs with loops.
- TazeTSchnitzel 13y agoAw, damn. I didn't realise it was all fake properties, I thought that would produce something.
- bzbarsky 13y agoNothing fake about accessor properties. Means you can lazily generate the string for .innerHTML and such, though!
- Shorel 13y agoLISP: (:ul (:li Hello))
- Shorel 13y agoNah. It would be much easier as a Lisp S-EXP. And yes, it has been attempted.
- __david__ 13y agohttp://jsml.org http://jsml.org