DEV Community


The clash between XML and JSON

jai_shankarn profile image Jaishankar ・3 min read

Alt Text

We all face confusion on deciding from the options on our every day with almost everything from which dress to wear, which restaurant to choose for lunch and which for dinner, which product to buy while shopping and the list keeps going on every day where we decide on the quality, quantity, cost, our mood or some influence and so on.

Likewise, whenever a new software project is started there would be a lot of technical questions arise, like, which technology platform to use, which database to use, how APIs can be written, should we do that or should we do this. And, after a few hot arguments among the team, everyone narrows down quickly to a list of top 2 or 3 options which would meet their projects requirement, cost, knowledge, and schedule. And these play a very important role in deciding which option to choose. There are products that have failed when people choose it as an option only because they liked it or it could’ve been in the trending one or even from someone’s influence and all these without considering the above which did not meet their project’s requirement.

XML or JSON - the never-ending comparison

Likewise the above comparison, the XML and JSON is compared when we need data to be stored and more importantly in a structured way. But why is this clash between these two comes up? Maybe, these are widely used, so we too should use one of these or maybe we have knowledge and experience on how to use/work with these data structures earlier or where the requirement actually needs it.

Why should we use XML and JSON?

XML (eXtensible Markup Language) has been in use for many decades and has many ways to validate and follow a defined schema. It has helped in defining a process in a structured way for many companies in streamlining their technologies. There are Xquery, Xpath which allows us to play around XML. And this can be loaded as a DOM object and easily traversed to any place to retrieve and update data. One just needs to learn the basic FIFO concept to edit any XML.
XML is widely used in:

  • Web publishing
  • Mobile applications
  • Web searching
  • Metadata applications

On the other hand, JSON (JavaScript Object Notation) is a structured syntax which is basically is key, value paired data. It can be parsed in almost all programming languages easily. There are a lot of databases that use JSON as their data structure so it could retrieve data at a great speed. It has gained popularity and attention in the last decade in many areas.
JSON is mostly used in:

  • Database
  • Configurations
  • Transferring data

Looking at the above, XML’s purpose is document markup, handling large/complex data. It gives semantic meaning to text through its tree-like structure and ability to represent mixed content. Having XML as your APIs response or as a configuration can be still done but that is not its purpose.

JSON’s purpose is structured data interchange. It serves this purpose by directly representing objects, arrays, numbers, strings, and booleans. Its purpose is distinctly not document markup. And moreover, JSON does not have a natural way to represent mixed content.

Companies use XML or JSON for their APIs and there are even few who use both in their APIs. Many desktop applications use XML only. Major databases which support XML (IBM DB2, Microsoft SQL Server, Oracle Database, PostgresSQL, BaseX, eXistDB, MarkLogic, MySQL) and major databases that support JSON (MongoDB, CouchDB, eXistDB, Elastisearch, BaseX, MarkLogic, OrientDB, Oracle Database, PostgresSQL).

Which one would be the future?

XML is a document markup that serves schemas and DTD that in my opinion could be used in document creation, manipulation, and storage. XML is still heavily used on the web for audiobooks, publishing. XML is even considered as a source from which other markup formats (ePub/x-Html) are converted. And on the other hand, there are a lot of new devices, products which have been developed in the Internet of Things that are smaller and less powerful than computers and will be in a need to exchange data across the web, the lighter and faster JSON would naturally be preferable to XML. Moreover, REST APIs, NoSQL databases, full-stack javascript, new methods of API development and with the increasing performance of JSON, I believe JSON will be more widely used and would replace XML in the software development field whereas XML will still continue strongly in serving the need for managing documents.

Discussion (1)

Editor guide
bias profile image
Tobias Nickel

hi, I am the author the fastest xml parser in Javascipt, I would still always recommend people to use json.