Let us understand the difference between JSON and XML web technologies. Here’s a brief overview on JSON vs XML with a complete description and examples as well.
XML
XML is an abbreviation for Extensible Markup Language and was developed by the World Wide Web Consortium.
XML is primarily used to store and transport data from one application to another application over the Internet.
XML format has become a standard for many of the daily tools that we use such as:
- Open Office
- Apple iWork
- Microsoft Office
- LibreOffice
The Simple Object Access Protocol (SOAP) widely used XML for inter connectivity and transporting data between multiple applications.
The file extension for XML documents is .xml.
Example:
XML typically looks like as shown in below example.
<car> <company>Maruti Suzuki</company> <name>Swift Dzire</name> <price>800000</price> </car>
JSON
JSON on the other hand is a lightweight data interchange format which is much more easier for computers to parse the data that is being transmitted.
JSON is developed by Douglas Crockford.
JSON format is self describing and is comparatively much easier to read than XML formatted documents.
JavaScript uses JSON.parse() function to convert JSON formatted string into native JavaScript objects.
JSON documents are essentially described using Name and Value pairs.
The file extension for JSON documents is .json.
Example:
JSON typically looks like as shown in below example.
{ "company": "Maruti Suzuki", "name": "Swift Dzire", "price": 800000 }
Difference between JSON and XML
Sr. No. | JSON | XML |
1 | JSON is an abbreviation for JavaScript Object Notation. | XML is an abbreviation for Extensible Markup Language. |
2 | JSON is a way of representing objects. | XML is simply a markup language. |
3 | JSON is designed to be more compact than XML and better for computers, and has a lot of advantages. | XML is designed to be more readable for humans, however, it has a lot of disadvantages over JSON. |
4 | JSON makes use of JavaScript kind of syntax with support of Lists, Dictionaries, etc. | XML uses tag structure to represent data items. |
5 | JSON is an object notation which includes support for object, frame and graph model. | XML is an inline markup format with hierarchical model. |
6 | JSON is a newer technology and it’s very lightweight and easy for parsing comparatively. | XML is an older version and is obviously a little inefficient for parsing. |
7 | The JSON format does not provide displaying data on a webpage as it can be seen in XML. | The XML format provides displaying data on a webpage, which helps to get an overview of the data that is being transferred to another application. |
8 | JSON being an advancement over XML provides an excellent efficiency even when compression is not used. | XML provides a disadvantage because it has a 21% overhead over JSON. |
9 | JSON technology should be used in small applications like games where there’s not much data transmission requirement. | XML is best for large E-Commerce websites where security is much more invested upon. |
10 | The data transfer rate is much better in JSON as compared to XML. | The data transfer rate is very low in XML as compared to JSON. |
11 | In JSON syntax, no end tag is used. (Please check the example below) | XML makes use of both the start and end tags. |
12 | JSON has to be parsed with a Standard JavaScript function which is eval() function. | XML has to be parsed with an XML parser, which is more time consuming. |
13 | JSON is an extension of JavaScript | XML is an extension of Standard Generalized Markup Language. |
14 | JSON does not supports comments. | XML syntax supports using comments |
15 | JSON does not provides any support for namespaces. | XML supports namespaces. |
16 | JSON technology is data oriented and can be mapped with data comparatively easily. | XML format is document oriented and mapping is a little difficult compared to JSON. |
17 | JSON files are very easy to read as compared to XML. This is essentially because it has name-value pairs instead of tags. | XML files are a bit clumsy when compared with JSON and therefore, it is little difficult to read and interpret XML documents. |
This article is submitted by Tushar Soni, he has a programming blog Coding Alpha.
Comment below if you have queries or found any information incorrect in above tutorial for difference between JSON and XML.