If you have more data than text, use JSON. If you have more text than data, use XML/HTML.
Imagine HTML documents encoded in JSON -- in that case JSON would be ugly and annoying to edit. Now imagine (the more common situation of) structured data serialized as XML. That is ugly and annoying to edit.
Use the right tool for the right job. :)
<Foo>Some text <Bar>more text</Bar></Foo>
while JSON does not. So there isn't a 1:1 mapping, at least not in the direction XML → JSON (and the other direction only works if you have a schema that defines data types for the document). {
'tag': 'Foo',
'children': [
'Some text',
{
'tag': 'Bar',
'children': ['more text']
}
]
}
or (hello, LISP) ['Foo', ['Some text', ['Bar', ['more text']]]]Also, side observation, that Lisp-like encoding is pretty icky as-is (deciding if something is a tag or text by how deep the array is?), and gets worse if the XML uses attributes.
'(foo "Some text" (bar "more text"))
I don't think your second example is much at all like Lisp and I think to actually achieve something lispy, JSON would need some kind of symbol type, so you can do:
['Foo, ['Some Text', ['Bar, 'more text']]]
Though, mix in attributes, and it's just a nightmare.After all, it's not like:
'(Foo "Some text" (Bar "more text"))
Or with an admittedly not-very-well-thought-out attribute: '(Foo "Some text" (Bar ([] (name "Baz")) "more text"))
For: <Foo>Some text <Bar name="Baz">more text</Bar></Foo>
Though there may be a better way of representing attributes....https://developer.mozilla.org/en-US/docs/Web/API/CDATASectio...