In Favor of XML Over JSON

Over the past few years, JSON has shed its Javascript beginnings and has become a popularly preferred method of data exchange in many scenarios over XML because it typically uses less characters than XML for its encoding and because of JavaScript’s native ability to interpret the strings into proper objects.

XML is increasingly being regulated to configuration files and as a platform-independent request and response for REST services, and of course XHTML. AJAX, while originally intended for XML, is being used to transfer JSON encoded data because of Javascript’s intrinsic transcription of JSON strings into Javascript objects. With the rise of Web 2.0, often with pages that use JSON with their AJAX calls, the JSON strings are built directly from the datastore.

Instead of building JSON strings, I posit that output from a datastore should be encoded as XML and never encoded straight to JSON. Pulling data and directly assembling a JSON string limits the reuse of the code, and the possible uses of the data in other contexts and applications. XML, by contrast, grants flexibility in data format decisions in any given present or future scenario. Outputting data formatted as XML allows the data to be more easily transformed into many different text-based encodings and presentations than pure JSON.

Using XSLT or even an XML parser on the outputted XML, a developer can transform the data into whichever encoding is needed for an application. With an added transformation layer, XML data can then be turned into XHTML for web browsers, CSV for legacy spreadsheets, PDF for printing, or even send the plain XML down to other platforms (e.g. Java, Flash, C) that can parse it. And as always, you can even transform the XML into JSON strings for nice, easy, lightweight data transfer and object creation in JavaScript or any JSON library-equipped language. XML is a great intermediate data-encoding format that remains human-readable and flexible enough to be easily transformed into any format that is required on the client, including JSON.

Taylor Gillespie
About Taylor Gillespie
Taylor is a Staff Writer for DevWebPro

2 thoughts on “In Favor of XML Over JSON

  1. Pingback: Burma's secret Karen genocide | Full Moon Party Thailand

  2. Pingback: My Blog Title

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>