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.
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.
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
JSON is mostly used in:
- 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).