JSON
Now a days json is common word in development. If someone who has no idea, don’t hesitate. Here is the introduction to JSON.
JSON (JavaScript Object Notation) is a lightweight data-interchange format.
JSON is representation of data in well structural manner. It use to interchange data over network.
Easy to read and write. Easy for machines to parse and generate.
USE:
- Often used for serializing and transmitting structured data over a network connection.
- It is used primarily to transmit data between a server and web application, serving as an alternative to XML.
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family languages.
It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects.
Internet media type: application/json
Filename extension: .json
Below is Introduction level example, demonstrate how JSON object can create and use in javascript.
Example:
How to declaration of JSON:
Syntax: var ObjectName = { “varName” : value};
var JSONObject = {
"name": "John Johnson",
"street":"Street 18",
"age":33,
"phone":"555 1234567",
"City": "Bhavnagar"
};
How to Access Json object:
In javascript,
alert(JSONObject.name );
alert(JSONObject.age);
alert(JSONObject.street);
alert(JSONObject.phone);
Json with Array:
var JSONObject = {
"name":"John Johnson",
"street":"Street 18",
"age":33,
"phone":"555 1234567",
“City”: “Bhavnagar”,
"address": {
"streetAddress": "21 2nd Street",
"city" : "New York",
"state":"NY",
"postalCode":"10021"
}
};
alert(JSONObject.name );
alert(JSONObject.age);
alert(JSONObject.address.streetAddress);
alert(JSONObject.address.city);