blog

Home / DeveloperSection / Blogs / Introduction to JSON

Introduction to JSON

Anonymous User5885 04-May-2012

JSON is smaller than XML, and faster and easier to parse. JSON (an acronym for JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript programming language for representing simple data structures and associative arrays, called objects. JSON is syntax for storing and exchanging text information.

JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

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 associative array.

·    An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

JSON is not only a syndication format (e.g. an alternative to XML); it is a language-independent data interchange format.

Why JSON?

For AJAX applications, JSON is faster and easier than XML.

Using XML:
·         Fetch an XML document
·         Use the XML DOM to loop through the document
·         Extract values and store in variables

Using JSON:
·         Fetch a JSON string
·         eval() the JSON string
JSON Syntax Rule:
JSON syntax is a subset of the JavaScript object notation syntax.
·         Data is in name/value pairs
·         Data is separated by comma
·         Curly brackets holds objects
·         Square brackets holds arrays

Example: In this example, simply I have created JSON object and store some values after then set these values into proper names.

<html>
<head>
                <title>JSON Object Creation Demo</title>
</head>
<body>
<h2>JSON Object Creation in JavaScript</h2>
<p>
Name: <span id="jname"></span><br />
Age: <span id="jage"></span><br />
Address: <span id="jstreet"></span><br />
Phone: <span id="jphone"></span><br />
</p>
<script type="text/javascript">
                      var JsonObject= {
                                                                "name":    "Arun Kumar Singh",
                                                                "street":    "Kothapaarcha",
                                                                "age":   22,
                                                                "phone":  "000 1234567"
                                                };
                                                document.getElementById("jname").innerHTML=JsonObject.name
                                                document.getElementById("jage").innerHTML=JsonObject.age
                                                document.getElementById("jstreet").innerHTML=JsonObject.street
                                                document.getElementById("jphone").innerHTML=JsonObject.phone
                </script>
</body>
</html>

 Now save this file in html format and open it with web browser.

Introduction to JSON


Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By