Skip to main content

JSON Introduction

Now a days, JSON has become a hot topic. Developers today are really getting interesting in JSON.

So, in this post I am going to explain what is JSON.

JSON : JavaScript Object Notation  is a technology / format to store the data in key - value pairs i.e. the large amount of data can be stored / transmit using a JSON.

Like for example : For a php developer, it is common to create the AJAX backend page and to send the data back to main page. Previously it was kind of tedious as user needs to create an array and needs to handle everything by himself / herself. But with JSON, it becomes very easy. JUST CREATE A JSON OBJECT containing the data, pass it to main page and use it.. simple.

and this is just a very basic example.

JSON is widely used in all Documents-Oriented Databases (like MongoDB[http://learnandsharetoall.blogspot.in/2014/01/what-is-mongodb.html], Hadoop, NoSQL etc.).
So JSON's application is very very much extended.

Now to understand JSON, lets divide it in four parts.

a) Basic Structure
b) Value Types
c) Complex Structures 

So Basic Structure, a basic JSON script contains a "KEY-VALUE" pair to represent the data.
for example

{
   "name" : "test",
   "country" : "India"
}

So above is the basic JSON script.
Starting and ending the script with curly braces {  and  and then key-value pairs separated by comma

Above name and country is key with values test and India.

So this is basic JSON structure, how a basic JSON looks like.


Moving on to value types , i.e. what are the types of values it can store.

So consider the below JSON,
{
     "name " : "Test1",
      "Age " : 22,
     "isMarried" : false
}


So the above JSON has 3 value pairs, name with String value, Age with Integer value and isMarried with boolean values.

So as we have seen, the JSON can store a wide variety of data.
Even the key in JSON can serve as individual JSON  Script and can also hold array of objects.(described in complex structure part)

Moving on to Complex Structures,

There can be two types of complex structures as told above.
a) Keys containing array of objects
b) Keys containing another JSON script(nested JSON)


Keys containing Array

Consider a JSON,
{
    "name  " : "test1",
    " country " : "india",
    "hobbies " : ["Music","Reading" , "Blah" , " Blah"]

}

So here a key hobbies containing an array of objects.So this, can be used to store the array of values.This can be really useful in real world applications.

Keys containing another JSON script(nested JSON)

Consider a JSON,
{
       " name " : "test1",
        "address" : {
                             "city" : "Noida",
                             "country" : "India"
                        }
        "DOB" : "28-feb"
}

So in above script,
address is the key which itself is the json object.

You can use these as


var s = {

       "name" : "test1",

        "address" : {

                             "city" : "Noida",

                             "country" : "India"

                        },

        "DOB" : "28-feb"

}

console.log(s.address);
   // This will print the address JSON

To get the city  console.log(s.address.city);

Combining the above two complex structure, we can create a JSON which contains key having arrays of JSON String.


Hope it helps.
Thanks.










}

Comments

  1. Hello , nice introduction post for JSON .
    Do follow up with its live implementation in javascript .
    Thanks and keep sharing . :)

    ReplyDelete
  2. yeah sure.. very soon i will post the live implementation..

    ReplyDelete

Post a Comment

Popular posts from this blog

Login with Google Account using PHP / Javascript using OAuth2.0

Login with Google Account using PHP with code This post have Complete Code for Login / Sign-in  with google Account  using PHP / Javascript with oAuth2.0 Basically today we have seen almost every website needs you to register yourself before you can post or take part in any discussions to the website. But it become a tedious task to register and login to many different sites. Solution is to provide the users the option to Login with existing Google / Facebook account as almost everyone have Facebook and Google account.. In this post, I am going to explain how to integrate the Google Login / Sign in  for your website. For this,  First you need to create your Client ID, Client Secret and your developer API key. For this go to https://developers.google.com/identity/sign-in/web/sign-in Click on the button Create Project. A new window will open up. Please select Create Project / or select already created Project. It will then ask for about type of Project. Please

How To Set Up Apache Virtual Hosts on Ubuntu

How to setup Virtual Host in Ubuntu 16 / Ubuntu 18 on localhost / local machine To run the website with host on localhost(With LAMP) becomes important in many cases. This blog post will demonstrate how to achieve this. Assuming you have LAMP already installed and reading the code from (/var/www/html) Follow the simple steps below Create the code base To Create the code, simply create a directory named localweb inside /var/www/html. Create a file index.php inside localweb directory Content of index.php file <?php  echo "Local Website"; ?> Now our code base is set, so we need to configure apache Go to apache directory cd  /etc/apache2/sites-available/ Create one file named localweb.conf with content <Directory /var/www/html/localweb/>     AllowOverride All </Directory> <VirtualHost *:80>     ServerAdmin admin@localweb.com     ServerName localweb.com     ServerAlias www.localweb.com     Documen

ORCAM - Blind can read too.!!

ORCAM: The technology that was developed mainly with the aim – to help to help the visually impaired and blind regain the functionalities that were lost. Yeah. So now even visually impaired guys can get to know even the smallest written things just by pointing towards them, like the reading the book. Yes. Even those who are completely blind, can even read a book using ORCAM. SO what actually is ORCAM.????? A visual system with human like performance to help visually impaired people Here is a look towards ORCAM-See for yourself Search Results It is a simple device with a camera and earphone   that fits in the simple glasses   and uses the Text-to-speech technology to read the objects and sends the user in the voice format with the help of the earphone. The   OrCam device is able to identify thousands of objects, including the faces of loved ones, dogs, buses, newspaper text and store signs, all with the point of the finger. Its v