JSON and its Working

JSON is the short form of JavaScript Object Notation, and it is a very good way to organize the information to store, and easily accessible. Briefly it is can be defined as; it gives a collection of information in the form of human-readable that you can access in a logical way.

Collecting JSON Data

To store data or information, JSON creates an object which can be accessed with the JSON variable. For this, you have to enclose the value of a variable in a curly brace, and defines it is the value of an object. Inside the curly braces, you can declare many properties using a method namely “name” “and its value”. If you want to access the stored information from the JSON, you can easily refer to the property which is needed.

document.write(student[1].name); // Output:Deepak
document.write(student[0].age); // Output: 20

Use Arrays to store JSON Data

Array is one of the most optimum ways to storing JSON Data or information. Sometimes it is more completed in the JSON language to store more than one people information in a single variable. And the array is structured Data Type that has the capacity to store multiple people information in a single variable, by setting its dimensions that needed. There are some examples array utilization in the below lines.

var student = [{
    "name" : "Deepak",
    "age" : "20",
    "gender" : "male"
},
{
    "name" : "Daniel",
    "age" : "21",
    "gender" : "male"
}];

For using this information, you needed to access the array index of that particular people which you want to access. For instance, you needed the following snippet to access information that already stored in the array.

document .writes(‘ Deepak is ‘ Deepak .age); //  its //output : Deepak is 24
document. writes(‘Deepak is ‘ Deepak .gender); // its //output : Deepak is male

Note- it is can be very beneficial if you use it with the loop. for loop can be best for it, because in for loop you can set it up desired number of time. And it is automatically increment and repeating a particular block of statement while the loop is not terminated.

Nesting JSON Data

To store many people information without using Array, then you can also use Nesting. It is another way to store multiple people information that would be nest objects. This is the example of storing multiple people information using nesting.

var student = {
 "Deepak" : {
 "name" : "Deepak Gupta",
 "age" : "20",
 "gender" : "male"
 },
 "Daniel" : {
 "name" : "Daniel Gensen",
 "age" : "21",
 "gender" : "male"
 }
}

It is very simple to access information from the nesting objects, and also understand its working, that describes in the following lines.

document.write(student.Deepak.name); // Output: Deepak Gupta
document.write(student.Deepak.age); // Output: 20
document.write(student.Deepak.gender); // Output: male

Sometimes both array and nested can be combined with each other, while needed a lot of necessary information to store.

Why does JSON matter?

When AJAX comes into the existence, it is become very important for sites to suitable to load information as quick as possible and in an asynchronous manners, or in the background without doing any page translation to serves. To transfer the information or contents within the current page without requiring the page refresh adds. And never added any inconvenience for the users. The popularity of social media in these days is going to up and up. There are many sites depend on the content facilitates by some sites such as Facebook, Twitter, Flickr, and many more. These sites gives RSS (Rich Site Summary) notifications that you can easily import and use on the server-side, but if you want try to load this with the AJAX, first of all you have to run it on the wall. If you want to load RSS feeds, then you can only do it only with the feeds. It is only possible with the same domain where it is hosted on. If are trying to load my Flickr accents a RSS feeds comes through the jQuery’s.

[Exception... " restricted URI cannot Access " code: 
"1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"
location: " <a 
href="http://www.j2eebrain.com/">http://www.j2eebrain.com/</a> Line: 19"]

In the JSON, it is possible to overcome the cross-domain problem. It uses a method namely JSONP also uses a function such as callback to transmit the JSON data to your domain. By using JSON there are many things you can easily do, that is previously not possible or very difficult. And you can think of the many possibilities with the JSON.

How you can Load JSON into a Project

 

$.ajax() is a method that use to easily load the JSON data over the internet applications.

$.ajax(
 type:’GET’,
 http://www.j2eebrain.com/
 data:"format=json&id=55",
 success:function(feed)
 {
 document.write(feed);
 },
 dataType:'jsonp'
);