The One Way XML Beats JSON
Let me start by stating I’m not a fan of XML. I find it to be too verbose, and as a developer who uses Javascript all day, I usually hate working with XML. The various libraries I’ve used to convert it into a usable format seem to fall short and do weird things like wrap arrays in variables called ‘$’.
By definition, Javascript and JSON just go together, and working with JSON makes my life simpler.
That said, I did recently come across one feature of XML that JSON just can’t compare to: storing data about data, also called metadata.
Let’s say we have an array in JSON:
A similar array in XML:
So far so good. The problem arises when you want to add information about each result. Say you want to add access control information. The xml could look like this:
There’s just no good way to do that in JSON. You could add a new attribute to each JSON result object, but that’s polluting the data with information ABOUT the data. If your data gets more complicated than a simple array, and you need metadata at different levels, it can get confusing very quickly.
There’s a few proposed ways to add metadata to JSON, but there’s no standard, which means there’s no tooling built around it. If you know otherwise, let me know.