In this guide, we will learn the differences and similarities between JSON and XML.
Before we see the differences between XML and JSON, lets see the example of a JSON file and the same data in XML file.
JSON Example
A simple example of a student array data in JSON format.
{"student":[ {"name":"Steve", "nickname":"Stevie"}, {"name":"Chaitanya", "nickname":"Chetan"}, {"name":"Ajeet", "nickname":"Jaat"}, {"name":"Lina", "nickname":"Lee"} ]}
XML Example
The same above example in XML document.
<students> <student> <name>Steve</name> <nickname>Stevie</nickname> </student> <student> <name>Chaitanya</name> <nickname>Chetan</nickname> </student> <student> <name>Ajeet</name> <nickname>Jaat</nickname> </student> <student> <name>Lina</name> <nickname>Lee</nickname> </student> </students>
JSON vs XML
SNO. | JSON (JavaScript Object Notation) | XML (eXtensible Markup Language) |
1 | JSON is simple and easier to read and write | XML is verbose and less readable |
2 | JSON doesn’t use end tag | In XML, the end tag is mandatory |
3 | JSON supports array thus it is easy to transfer a big chunk of homogeneous data items using JSON | XML doesn’t support array |
4 | JSON is easier to parse and can be parsed to ready-to-use JavaScript object | XML is difficult to parse than JSON |
5 | JSON is short | XML document is lengthy, verbose and redundant |
6 | JSON is less secure than XML | XML is more secured than JSON |
7 | JSON file is more readable than XML because it is short and to the point. | XML file is big and filled with user-defined tags, thus less-readable |
8 | JSON is data-oriented | XML is document-oriented |
Similarities between JSON and XML
1. Both JSON and XML are human readable language.
2. Both JSON and XML support unicode, thus any human written language can be written in JSON and XML documents.
3. Both JSON and XML can be parsed.
4. The data in both JSON and XML can be fetched using XMLHttpRequest.
Leave a Reply