Tim has an interesting post comparing JSON and XML that has me wondering about several things.
Here are some specific questions I have with the piece:
1. I don't see any reason why JSON has different streaming characteristics than XML. Every JSON parser I've written has a streaming I/O layer at the bottom and defers buffering (and type mapping) to a layer above, just like most modern XML stacks. Why is XML inherently more streamable?
2. Like Joe Gregorio states in the comments on Tim's post, I also prefer JSON's simplification of only allowing UTF-*-based encoding.
3. Tim states that you should use XML when the order of data matters, but JSON has a perfectly reasonable ordered compositor (arrays) that gets used a heck of a lot.
4. I'm also not buying the JSON isn't extensible argument. There's nothing stopping the consumer of a JSON value from ignoring fields whose labels don't make sense. Yes, this requires using convention to avoid namespace collision, but I'm not convinced this is such a bad thing after living for almost a decade with XML namespaces.
5. As for text handling, the things I love about JSON (vs. XML) are you can trivially distinguish numbers from text-that-looks-like-a-number and more importantly, you can represent strings that contain control characters without resorting to base64 encoding. I also don't miss the ambiguity of significant vs. insignificant whitespace. With JSON, it's obvious from the data. With XML, you need a DTD or schema to know for sure. Tim's defintely Mr. Text so I'm sure he'll tell me that I'm wrong to want these features :-)
6. As for renderability, I fail to see how this: { “FirstName”: “Tim”, “LastName”: “Ewald” } is inherently any less renderable than the XML equivalent (I'd type it in here but for the life of me I can't get .TEXT to escape things correctly). Yes, I can apply an XSLT to the latter to produce HTML, but what if I'm a Swing or AWT or User32 or Avalon user?
In short, I think the biggest advantage to XML over JSON is inertia. XML is here, there are tons of tools, and there is a ton of data.
JSON has a huge hill to climb to displace XML for new applications that don't already have a Javascript/Browser component (thanks Dare).
That stated, it has simplicity and fashion trends on its side.
Posted
Jan 03 2007, 08:25 AM
by
don-box