JSON

JSON vs. XML

JSON vs. XML

This section highlights the difference between JSON and XML. JSON and XML are both data exchange formats and both are heavily used. JSON object has a type whereas XML data is devoid of type. JSON cannot display data whereas XML offers the capability to display data. JSON is not secured whereas XML is more secure compared to JSON. JSON supports only UTF-8 encoding whereas XML supports many encoding formats.

The following table gives differences between XML and JSON.

Let’s see a sample JSON Code of an employee record

{
  "employee": [ 
     { 
        "id":"55027104", 
        "name": "Abhijit", 
        "lastname": "Sawant",
        "email-id": "abhijit.sawant@xxx.com"
        "address": "C-175, Defence Colony, New Delhi 110026"    		
     }, 
     { 
        "id":"55027107", 
        "name": "Mouni", 
        "lastname": "Roy",
        "email-id": "mouni.roy@xxx.com"
        "address": "B-128, Swasthya Vihar, New Delhi 110092"    		
     } 
  ]   
}

Now see the same code written in XML.

<?xml version="1.0" encoding="UTF-8" ?>
<root>
	<employee>
		<id>55027104</id>
		<name>Tom</name>
		<lastname>Price</lastname>
		<email-d>abhijit.sawant@xxx.com</email-id>
		<address>C-175, Defence Colony, New Delhi 110026</address>
	</employee>
	<employee>
		<id>55027107</id>
		<name>Mouni</name>
		<lastname>Roy</lastname>
		<email-d>mouni.roy@xxx.com</email-id>
		<address>B-128, Swasthya Vihar, New Delhi 110092</address>
	</employee>	
</root>

You can clearly see that JSON is far more readable and compact as compared to XML.