What is XML?
XML(Extensible markup language) is a data-interchange format.In this format values is surrounded with start and end tags.Xml is derived from SGML(Standard Generalized Markup Language). This format is used for to sending data from one computer to remote computer in a network.It is easy to read and write for humans. For parsing xml data, we use xml parsers. This parsers verify that particular xml file well-formed and valid based on respective DTD(Document Type Definition) file.
Disadvantages with XML:
1.It doesn't support data types.
2.Its XML parser takes more time to process the XML file.
3.File size is limited.
4. For storing xml data to object and vice-versa is high cost process.
5.This format is not good for sending data from client to server or vice-versa.
To over come above problems JSon is used.
What is JSON ?
JSON(JavaScript Object Notation) is a lightweight data-interchange format.It is easy for humans to read and write and easy for machine to parse and generate.This JSon is developed from JavaScript programming language,standard ECMA-262 Edition December 1999.JSON is a text format that is completely language independent.
How many ways we can write JSON ?
We can built JSon in two ways.
1.Collection of name/value pairs.In various languages,this is realized as an object, record, struct, dictionary, hash-table, key-list, or associative array.
2. An ordered list of values.In most languages this is relialized as an array,vector,list or sequence.
This are universal data structures.Virtually all modern programming languages support them in one form of another. It makes sense that a data format that is interchangeable with programming languages also be based on this structure.
Advantages of JSon:
1.This format is supported by every browser and parser is parsing data very fastly.
2.To send data from client to server or vice-verse JSON is better than XML.
3.It store data in form of name /value pairs.
4.JSon is used for consumption of data in web applications from webservices for its size and ease of use.
5.JSon is Data-oriented,so so JSon is easily mapped with object-oriented systems.
6. A browser JSon is faster for serializing and de-serializing.
Example :
I have xml file file like below
<order>
<itemno>10</itemno>
<itemName>LUX</itemName>
<qty>2</qty>
</order>
Now i am converting XML to JSon
Syntax of JSON file:
{
-----
-----
-----
}
Example 1:
json1.json:
{//start
{
"order": {
"itemno": "10",
"itemName": "LUX",
"qty": "10" (Donot
give coma (,)for last field)
}
}//end
The above format is Object format
and below format is Array format
Example 2:
json2.json:
{
"order": [
{
"itemno": "10",
"itemName":
"LUX",
"qty": "10"
(Donot give coma (,)for last field)
}
]
]
}
Example 2:
{
"array": [ 1, 2, 3 ],
"boolean": true,
"null": null,
"number": 123,
"object": {
"a": "b",
"c": "d",
"e": "f"
},
"string": "Hello World"
}
If you want validate your
JSON, copy and paste your json in this site
www.jsoneditoronline.org
http://jsonlint.com/