JSON vs XML



Let see how JSON and XML look when we store the records of 4 students in a text based format so that we can retrieve it later when required.

JSON style:

{"students":[   {"name":"John", "age":"23", "city":"Agra"},   {"name":"Steve", "age":"28", "city":"Delhi"},   {"name":"Peter", "age":"32", "city":"Chennai"},   {"name":"Chaitanya", "age":"28", "city":"Bangalore"}]}

XML style:

<students>  <student>    <name>John</name> <age>23</age> <city>Agra</city>  </student>  <student>    <name>Steve</name> <age>28</age> <city>Delhi</city>  </student>  <student>    <name>Peter</name> <age>32</age> <city>Chennai</city>  </student>  <student>    <name>Chaitanya</name> <age>28</age> <city>Bangalore</city>  </student></students>

As you can clearly see JSON is much more light-weight compared to XML. Also, in JSON we take advantage of arrays that is not available in XML.