I hear people saying “JSON is great, XML is over”, but I don’t hear XML partisans saying anything bad about JSON. There are two arguments that are over, though.

It seems to me that the great thing about JSON is that it exists for one purpose: to put structs on the wire. With XML, on the other hand, it’s assumed that you might want to stream it in by the gigabyte, or load it into one of a many different in-memory data structures, or run a full-text indexer over the contents, or render it for human consumption, or, well, anything.

Given JSON’s single-purpose design, generating and parsing it ought to be faster than with XML; but on the other hand, there aren’t that many apps where parsing and unparsing are a significant part of the workload.

XML’s internationalization is more thorough; it requires you to think about how you’re encoding the characters, and lets you use ISO-8859 or JIS or whatever if that’s your world. Also, while it’s not in the spec, every XML parser I’ve seen says “I’ll figure out the encoding in the incoming doc, and take care of it, and all you’ll ever see is UTF-X”, where “X” is 16 for Java and C#, 8 for almost everything else. I look at the Ruby JSON library, for example, and I see all these character encoding conversion routines; blecch.

Use JSON · Seems easy to me; if you want to serialize a data structure that’s not too text-heavy and all you want is for the receiver to get the same data structure with minimal effort, and you trust the other end to get the i18n right, JSON is hunky-dory.

Use XML · If you want to provide general-purpose data that the receiver might want to do unforeseen weird and crazy things with, or if you want to be really paranoid and picky about i18n, or if what you’re sending is more like a document than a struct, or if the order of the data matters, or if the data is potentially long-lived (as in, more than seconds) XML is the way to go.

It also seems to me that the combination of XML and XPath hits a sweet spot for data formats that need to be extensible; that is to say, it’s pretty easy to write XML-processing code that won’t fail in the presence of changes to the message format that don’t touch the piece you care about.

The Arguments Are Over · There used to be an argument about whether platform-neutral, language-neutral data formats were important, or whether distributed objects were the right answer. That’s over: HTML, XML, JSON.

There used to be people who argued that network interchange formats shouldn’t be text-based, but use binary where possible, for efficiency. That’s over: HTML, XML, JSON.