It would be nice to remove "fast" word since it brainwash populous without good reason.
I am not sure has anyone on site tried to compare JSON and XML against each other, but my conclusion was totally opposite.
On the chain web server - network - reader - browser rendering the XML is a winner on ALL tiers.
Why? The answer on all is "native support". I.e. no interpreters involved, all compiled and multi-threaded, polished to perfect in memory and CPU use:
- web server - back-end serialization could start from DB
level. In most DB XML is one of native outputs. Than Object
serialization. While on ALL platforms there are zillions of
implementations, most platforms are supporting XML as embedded API.
Java, .NET, PHP, name it.
ANY popular enough "Middle" tier on server (the one which does the business and UI logic) has support for use the XML as data holder.
- Network. On network JS people are counting each byte. And JSON looks less polluted with unnecessary text. But hold, in production all content goes over gzip-ed stream. And surprize! XML actually has few bytes smaller footprint.
- Reader. Browser needs to parse data. XHR has XML support and EACH implementation uses native (C-based xml lib) code. As result it could process larger amount of data with smaller CPU and memory use. XML gives 100 times faster and 100 times larger data volume. That is right. JSON will die on 100K records, XML will hold 10 times more.
- Browser rendering. What rendering API does support multy-threading and native code? JS+JSON? No way. Answer is XML+XSL.
In addition to run-time (lazy) rendering of heavy UI it gives extra
option: rendering before page is loaded. And with speed no JS could be
For startup where people are working on all tiers, having same data format and API is quite development time saver. As mentioned, XML has support on all, JSON - on some platforms. Documentation and feature set for XML is way behind of what JSON could offer. From validation against schema to encoding.
For large projects communication between tiers has become more important. Cross-team development speed relies on strict data format and validation, performance on data transformation, same data/API on different platforms, etc. XML has it all. JSON - no.
Could you have JSON be applied in all or at least in half? No.
Analysis on why JSON has become so popular and advertised is out of scope of this review. Industry is not always going the rational ways.