- Java Script Object Notation.
- This format data interchange is created by Douglous Crockford.
- This is similar to xml format data.
- In Xml the data is represented by tags but in Json the data is represented by key value pair.
- The name came from java script objects.
- In XML, a object of type student cabn be defined as follows,
- In Java Script one object can be created in two ways:-
- Function approach :- A function is created in javascript and then through new key word one can create a object.
example,
var Student = function( inputname, inputclass ){
this.name = inputname;
this.class = inputclass;
};
The Of type Student can be create as,
var Sandeep=new Student(“Sandeep”,”10th”);
Here Sandeep is a object of type Student .
- Unanimous approach:-
var Sandeep={
“name”:”Sandeep” ,
“class”: “10th”
};
- In JSON We can define a set of student like,
var data=[
{ “name”:”Sandeep” , “class”: “10th”},
{ “name”:”Sumanata” , “class”: “12th”},
{ “name”:”Sangeeta” , “class”: “10th”},
{ “name”:”Surabhi” , “class”: “8hth”}
];
- Most browsers support JSON.parse(), which is defined in ECMA-262 5th Edition . Its usage,
var json = data,
obj = JSON.parse(json);
- the browsers that don’t support JSON one can implement it using json2.js.
- for jquery getting the server response as json from ajax call can be handled like,
$.getJSON(url, function (json) {
$.each(json., function (i) {
//iterate the data
});
});