JSON
Introduction
JSON stands for
JavaScript Object Notation is one of most import scripting language. It is a
lightweight text-based open standard designed for human-readable data
interchange. JSON file contains .json extension. JSON contains concept of
key/value pair like concept of mapping in Java. In case of JSON its object
holds key/value pair. Each key of JSON is taken as a String but value of JSON
is of any type. Each key and value is separated by Commas.
What is JSON
- JSON stands for JavaScript Object Notation.
- It was designed by Dougals Crockford.
- It saves with .json extension.
- It was designed for human-readable data interchange.
- JSON supports array, object, String, number and values .
- JSON is easy to read and write than XML.
- JSON is language independent .
Note: Because of JSON
supports data structures like object and array. So it is easy to write and read
data from JSON.
Difference Between JSON and XML
Difference Between JSON and XML
JSON | XML | |
---|---|---|
Stands for JavaScript Object Notation | Stands for extensible Markup language | |
Easy to read | Less easy to read | |
JSON is data-oriented | XML is document-oriented | |
JSON is less Secure than XML | XML is more secure than JSON | |
Example: { "company": Volkswagen, "name": "Vento", "price": 800000 } |
Example:
<company>Volkswagen</company> <name>Vento</name> <price>800000</price> </car> |
Example:
Step 1: Design HTML Page
<body>
<p>JSON Practice :</p>
<p id="hiddendata">Vinodam#Rakesham#Madanam</p>
<p id="salary">5000#6000#7000</p>
<p id="demo"></p>
</body>
Step 2: Write Script
<script>
var hiddenvalue=document.getElementById('hiddendata').innerHTML;
var hiddensal=document.getElementById('salary').innerHTML;
var hiddensalary=hiddensal.split("#");
var hiddenval=hiddenvalue.split("#");
var employee=[
{"name":hiddenval[0],"age":21,"salary":hiddensalary[0]},
{"name":hiddenval[1],"age":22,"salary":hiddensalary[1]},
{"name":hiddenval[2],"age":24,"salary":hiddensalary[2]}
];
var i;
var emp="";
for(i=0;i< employee.length;i++){
emp +=employee[i].name +"<br>"+employee[i].age +"<br>"+employee[i].salary+"<br><p>**********</p>";
}
document.getElementById("demo").innerHTML=emp;
</script>
for live demonstration click here
Comments
Post a Comment