This comes up once in a while. Why use JSON instead of XML? Why choose one over the other? They seem so alike and yet I still find people discussing the perks of the two. Here I will give some points on the differences of the two.
EXtensible Markup Language Also known as XML is a markup language aimed at creating documents. However what it is mostly used for is, storing data in a structured way. Common XML implementations are: RSS, XHTML and SOAP. It is often used to transfer serialized data between systems - which can be read from any programming language. XML was developed in 1996 and you can define and use different data types in xml using a schema.
Something that both JSON and XML share is that they are readable by humans as well as machines.
So which one to use?
These are the things that I think are JSON's strengths - over XML:
- JSON is smaller in size (byte wise)
- The name of an element is only written once (There is no closing tag). Again this makes it smaller, less is more.
- JSON has arrays which easily define lists
- XML can have attributes on it's elements, which sometimes can lead to some questions - should attributes be parsed the same way as elements? When/why use attributes at all?
- In JSON it is easy to distinguish between numbers and letters. Such as "123" vs 123.
My preference as you might have figured out by now - is JSON. Am I wrong in my bias? please let me know in the comments :)
ps: I also have my own online JSON to XML converter