Difference between JSON and XML
Hey guys! We come across JSON and XML many times while parsing data through Internet.
So here I am to make you more aware when to use JSON and XML
In this post I am going to discuss the prime differences between JSON and XML
JSON
- JavaScript Object Notation.
- It is used for data exchange over the internet which is human as well as machine readable.
- Web services and APIs make use of JSON while making data available to public.
- It is machine independent.
- Light weight. So uses less data via transmission over the internet.
- Can store only classical data types like numbers and text.
- Easier to parse and read.
- {} indicates JSON object and [] indicate JSON array.
- Used to transmit data without formatting using primitive data formats.
example:
{
"employees": [
{
"name": "Erik Cyrus",
"gender": "male"
},
{
"name": "Anny Sun",
"gender": "female"
}
]
}
XML
- eXtensible Markup Language
- Makes use of tags. These tags are user-defined. Hence the language is extensible.
- Machine and human readable.
- Used to define data structures and in webservices.
- The tags are written within < > brackets.
- We can define our own tags i.e. <name>, <birthdate>.
- As it has starting and ending tags, it is slower than JSON while transmitting over the internet.
- No different notations for arrays
- It is better for sharing documents, because it allows datatypes like graphs, images, charts.
example:
<employees>
<employee>
<name>Erik Cyrus</name>
<gender>male</gender>
</employee>
<employee>
<name>Anny Sun</name>
<gender>female</gender>
</employee>
</employees>
Hence both have their merits and demerits, it solely depends on the developer what to use what?
Hope you liked my article. Feel free to share your views.
Have a good day!