Tuesday 3 November 2015

JSON and Its Advantage over XML

JSON

JSON stands for JavaScript Object Notation. JSON objects are used for transferring data between server and client, XML serves the same purpose.

JSON basically has key-value pairs.

employee = {
   "firstName" : "rajesh",
   "role" : "developer",
   "age" :  "25"
};

Features of JSON:

It is light-weight.

It is language independent

Easy to read and write

Text based, human readable data exchange format

Why use JSON?

Standard Structure: Standard structure of JSON objects makes developers job easy to read and write code, because they know what to expect from JSON.

Light weight: When working with AJAX, it is important to load the data quickly and asynchronously without requesting the page re-load. Since JSON is light weighted, it becomes easier to get and load the requested data quickly.

Scalable: JSON is language independent, which means it can work well with most of the modern programming language.

Let’s say if we need to change the server side language, in that case it would be easier for us to go ahead with that change as JSON structure is same for all the languages.

JSON vs. XML

JSON style:

{"students":[
   {"name":"Rajesh", "age":"25", "city":"Mathura"},
   {"name":"Sattu", "age":"26", "city":"Delhi"},
   {"name":"Rahul", "age":"28", "city":"Agra"},
]}

XML style:

<students>
  <student>
    <name>Rajesh</name> <age>25</age> <city>Mathura</city>
  </student>
  <student>
    <name>Sattu</name> <age>26</age> <city>Delhi</city>
  </student>
  <student>
    <name>Rahul</name> <age>28</age> <city>Agra</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.


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...