JSON Basics for Beginners

JSONJSON Basics

In this article we will learn: 

  • What is JSON?
  • Benefits of using JSON
  • A simple demo for using JSON.

So lets start with  WHAT IS JSON?

JSON stands for Java Script Object Notation…It is called that because storing data with JSON creates Java Script object . This Java script object can easily be parsed with JavaScript .JSON is a data  interchange format. Data is represented in form of key/value pair .

JSON is built on two structures 

  • A collection of name/value pairs.

–In various languages , this is realized as an object , record, struct , dictionary , hash table, keyed list or                    associated array.

  • An ordered list of values.

— In most languages , this is realized as an array , vector list or sequence .

  • var Student = {“name” : “xyz”, “marks”:89};

-You can see that JSON object follows key-value pair mechanism.

-Key should be  always string.

-Value may be string , number , Boolean or an Object .

 

JSON

You can have value of JSON object as value of another  JSON object as well ….

JSON2

For more understanding let us perform a simple demo .

  • Open Visual Studio.
  • Create a new project .
  • Web -> Empty Web Application .

JSON1

  • Go to Solution Explorer and create New Directory called Scripts
  • Go to following link and download JQuery Scripts.

JSON4

Add JQuery File to Script folder .

JSON5

Right Click on your project ->Add new item ->HTML Page

JSON6

Open Demo.html Page and  in the body add following code 

 

JSON7

In the head section add reference of JQuery Script file and create Javascript function as follows .

JSON8

That’s it !!!! Run the Page and check the Output.

Now let me tell you why are we using JSON.. WHY JSON?????????????????????

  • For AJAX application JSON is faster and easier than XML.
  • Fully automated way of serializing /de-serializing Javascript object .
  • Supported by AJAX toolkits and Javascript libraries.
  • Very good support by all browsers.
  • IOS provides native support for JSON not for SOAP.
  • Android support JSON but no support to SOAP based web services.
  • Switching up the contents of certain element within our layouts requiring  a page refresh adds a “wow” factor to our application .

 

JSON allows us to overcome the cross-domain issue because we can use method called JSONP that uses a callback function to send JSON Data back to our domain .It’s this capability that makes JSON so incredibly useful , as it opens up a lot of doors that were previously difficult to work around .

I hope this article is useful for you . Happy Coding!!!!

Leave a Comment

Your email address will not be published.