3 ms·
> JSON for lists, XML for trees No. JSON is a recursive data structure that can represent trees as well. It's easy to make a concise representation of DOM tree
by m1el 7y ago
> JSON for lists, XML for trees
No. JSON is a recursive data structure that can represent trees as well.
It's easy to make a concise representation of DOM trees as JSON: http://m1el.github.io/jsonht.htm http://m1el.github.io/jsonht.htm
I find it really sad that people don't know or consider s-expressions to represent trees.
(Department {:name "Scranton Branch"}
(Employee {:name "Michael Scott" :title "Regional Manager"}
(Department {:name "Sales"}
(Employee {:name "Dwight Schrute" :title "Ass. Regional Mgr"})
(Employee {:name "Jim Halpert" :title="Head of Sales"}
(Employee {:name "Andy Bernard" :title="Sales Rep"})
(Employee {:name "Phyllis Lapin" :title="Sales Rep"})))
(Employee {:name "Pam Beesly" :title "Office Administrator")))
- mdtusz 7y agoThere's a beautiful symmetry between s-expressions and XML which is why it's not really all that annoying to work with once you approach it as an s-expression.
- wry_discontent 7y agoWorking with Clojurescript and Reagent (or Hiccup) has ruined JSX for me. It's so verbose and absurdly hard to work with relatively.
- postalrat 7y agoWhy is JSX so much more verbose? The end tags?
- wry_discontent 7y agoIt's primarily the end tags, yes, but there's also the className shorthand in reagent that's nice. [div.btn.blue.p-4 {:disabled true} "Button Text"]
- gambler 7y agoThis reminds me of an old joke about binary XML: <byte> <bit>1</bit> <bit>1</bit> <bit>0</bit> <bit>1</bit> <bit>0</bit> <bit>1</bit> <bit>1</bit> <bit>0</bit> </byte> >It's easy to make a concise representation of DOM trees as JSON: http://m1el.github.io/jsonht.htm http://m1el.github.io/jsonht.htm It is not concise. Here is an example of a single div tag overhead: ["div",{"class":"some classes"}, ... ] <div class="some classes"> ... </div> Also, it does not represent DOM trees as JSON. It represents DOM trees as S-Exressions encoded via JSON. The s-expression above can be written directly as: (div (class= "some classes") ... ) So why does it need to be wrapped in a format that's verbose, underspecified, doesn't have comments, doesn't have namespaces and doesn't have any notion of metadata?
- m1el 7y ago> So why does it need to be wrapped in a format that's verbose, underspecified, doesn't have comments, doesn't have namespaces and doesn't have any notion of metadata? Because the OP article doesn't even consider s-expressions, so I'm working with the tools I was given. Personally, I find it frustrating that EDN (or some other form of s-exprs) aren't widely adopted.
- otabdeveloper4 7y agoNot specified enough, I think you mean: <ieee-754:byte xstdversion="2008" nstid="two's complement" _archext="x86-64"> <ieee-754:bit arity="2">1</ieee-754:bit> <ieee-754:bit arity="2">0</ieee-754:bit> ...
- hashbig 7y agoThis reminds me a lot of Elm's syntax.