4 ms·
> For me the only thing that JSON got better is that JSON is directly mapped to commonly used data structures: arrays and maps. This is nice, but it's also kin
by moron4hire 10y ago
> For me the only thing that JSON got better is that JSON is directly mapped to commonly used data structures: arrays and maps.
This is nice, but it's also kind of a pain, as it makes you have to stop and think about which structured data elements it's capable of supporting and which you have to send your own metadata through the wire and then reconstruct on your own. For example: Dates. Which is a shame. If there is one data element I want the most help with serializing/deserializing, it's freaking Dates. All the other ones are super easy in comparison. There's just way to much subjective, dirty, human culture tied up in Dates.
The only thing that I think is objectively better in all cases about JSON over XML is the less verbose end-structure syntax. I think XML only has Attributes because Tags have this silly need to state their name both as they enter and exit the room.
<Tag1 attr1="hello" attr2="world">
<Tag2>how</Tag2>
<Tag2>are</Tag2>
<Tag2>you?</Tag2>
</Tag1>
For simple, unnestable data elements, having the more efficient Attribute starts to look attractive.
If XML were more the form:
<Tag1 attr1="hello" attr2="world">
<Tag2>how</>
<Tag2>are</>
<Tag2>you?</>
</>
It's actually only one more additional, required character to add than if the attribute value were specified as an element instead.
<Tag1>
<attr1>hello</>
<attr2>world</>
<Tag2>how</>
<Tag2>are</>
<Tag2>you?</>
</>
Heck, why stop there? Do we really need to have quite all of those angle brackets now? How about we just get rid of all the ones we can assume:
<Tag1
<attr1 hello>
<attr2 world>
<Tag2 how>
<Tag2 are>
<Tag2 you?>
>
And finally, who even likes angle brackets? I've never enjoyed the dual duty they play as delimiters in XML and operators in other languages. Let's use a common set delimiter, something like square brackets or maybe parentheses.
(Tag1
(attr1 hello)
(attr2 world)
(Tag2 how)
(Tag2 are)
(Tag2 you?))
Now where have I seen this before?
PS: JSON that is as nearly as equivalent as I can make it is not much less verbose than original XML, and requires some level of convention to make up for the differences:
{Tag1: { attr1: "hello", attr2: "world", children: [
{Tag2: "how"},
{Tag2: "are"},
{Tag2: "you?}]}
Though I'm sure in common practice it'd have a lot of the original metadata of the XML version thrown away:
{attr1: "hello", attr2: "world", children: [
"how",
"are",
"you?"]}
- deleted 10y ago[deleted]
- mbrock 10y agoThe XML tag style is much, much easier to work with when you're dealing with markup. And XML's purpose is to be an Extensible Markup Language. It's way more appropriate than JSON or S-expressions for that. (Do you prefer to write HTML documents as S-expressions?)
- kccqzy 10y agoYes. With good tooling (such as Emacs), markup is much more pleasant to write in S-expressions than XML.
- wtbob 10y ago> Do you prefer to write HTML documents as S-expressions? Actually, yes. I use CL-WHO[1] a lot, in which one can write: (:html (:head (:title "Foo bar") (:link :rel "stylesheet" :href="baz.css")) (:body (:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ullamcorper efficitur purus, at suscipit nunc luctus vitae.") (:ol (:li "Cras vel est accumsan, malesuada leo eu, iaculis nulla.") (:li "Proin nec mi feugiat, posuere enim in, vehicula erat.") (:li "Morbi vitae purus nec neque posuere pharetra ultricies in nibh.") (:li "Nam maximus lectus faucibus, ullamcorper lectus aliquam, aliquam lectus.")))) Which I contend is prettier than the equivalent HTML. [1] http://weitz.de/cl-who/ http://weitz.de/cl-who/
- mbrock 10y agoI like S-expressions too, especially when generating markup programmatically. For hand-writing HTML/XML documents, which I do quite a lot, I really enjoy the tag style because of the verbose end tags and the ease of moving blocks. It's at least nice enough to make me annoyed when people claim the tag syntax is some horrible stupid disaster compared to S-expressions or (worse) JSON.
- 10y ago