Regarding response data formats, xhtml has the advantage of being both html (a format browsers know how to handle) and xml (a format that is well structured and parsable.) Semantically, xhtml can represent all of the same data structures/types as JSON: lists are UL elements, dictionaries are OL elements, numbers, strings, and booleans are really just strings in both, objects are really just dictionaries, and nulls in…
>xhtml has the advantage of being both html
>(a format browsers know how to handle) and
>xml (a format that is well structured and parsable.)
And where is the advantage in that over JSON? It's just a Javascript object and browsers know very
well how to handle it. That's the point. >Semantically, xhtml can represent all of
>the same data structures/types as JSON
XHTML has HTML semantics, i.e. it's intended to be used to mark the structure of the text. It has no advantage
for a general purpose data exchange. >dictionaries are OL elements
Nope. Or did you think about DL/DT/DD? Still nope. >numbers, strings, and booleans are really just strings in both
Nope. In JSON only strings are strings. Numbers, booleans and null are Javascript numbers, booleans and null. >objects are really just dictionaries
Objects are objects. Entire JSON response is an object, you can assign it to variable and use straight away. >and nulls in xhtml can be a special string as in JSON or an empty element.
As I said, nulls in JSON are Javascript nulls, not "some special string". >In both cases, the client has to either already know about
>the data structure and how to navigate it, or can treat it
>generically. XHTML has an advantage here; every data item
>can be labeled with an id or class attribute to make it
>easier to find. You can't do that in JSON unless everything
>is a dictionary value.
Uhm. If we are talking about data in key-value then JSON has a huge advantage there. Not only you can do it in JSON, but
you do exactly that and with very little overhead—that's exactly what makes JSON so attractive and popular.var article = {"title":"Adventures in JSON land", "authors":[{"name":"Jane Doe"}], "published":false, "tags":["JSON", "Javascript", "data format"]}.
That's it. Want to access your data? It's right there:
article.title -> "Adventures in JSON land"
article.authors[0].name -> "Jane Doe"
article.tags.length -> 3
Now do the same in XHTML and you will have much better understanding what advantages of JSON are.