The simple answer to this question is – both, now what’s the real question.
The real question is far more complicated and should be something along the lines of “Is XML or JSON best to do …”. Given the specific context of what and how data requires formatting, it is easier to identify the most appropriate technology because there is no real default. They both have there advantages and disadvantage – some of which are identified later.
- Abstract Syntax Notation One (ASN.1) – Variety of encoding rules including XML
- YAML Ain’t Markup Language (YAML) – Super-set of JSON
- Simple Declarative Language (SDL)
- Virtual Token Descriptor (VDT)
- Simple Outline XML (SOX) – Compressed XML
Some of the pros and cons of XML and JSON include:
- As of the end of last year JSON had a defined mechanism for defining a JSON formatted object in JSON-Schema but it had not been standardised.
- XML is a more verbose format but not without purpose. The syntax allows for the recording of relationships in a way that is meaningful to the dataset itself and not just as a property of an object or element in an array.
- XML is a collection of technologies including XSD (Schema definition), XSL-T & XSL-FO (Transformation techniques), XQuery, XPath, the list goes on.
- JSON has also spun off a number of associated techniques such as JSON-LD (Linked Data sets), JSON-RPC and, not to forget, JSONP (JSON with Padding). The latter being a device for circumventing a web browser’s same-origin security policy (SOP) when issuing an AJAX call to a foreign domain. This issue has since been eased through the adoption by the leading web browsers of Cross-origin resource sharing (CORS), which became a W3C recommendation early this year.
Nowadays, JSON is a well and widely supported format and is often the default position. However, between distrusted parties, over unreliable communications or between vastly different technologies, XML provides a standards-base, validate-able (XSD) and adaptable (XSL-T/-FO) data format.
So, in brief to answer the original question – it depends!