JSON Introduction

Introduction 

  • JSON is a lightweight data-interchange format.
  • JSON format is easy to understand.
  • It is used to read and write for humans in very easy manner.
  • It is also easy for machines to parse and generate.
  • It is a subset of the JavaScript Programming Language.
  • It is text format that is completely language independent.

Structure

JSON is built on two structures.
  • A collection of name/value pairs.
  • An ordered list of values.

These are universal data structures.

Forms 

In JSON, they take on these forms:
  • An object is an unordered set of name/value pairs.
  • An object begins with { (left brace) and ends with } (right brace).
  • Each name is followed by : (colon).
  • The name/value pairs are separated by , (comma).
Example for running JSON in HTML

The following example shows how to use JSON to store the information related to courses based on their name and tutor.
  1. <html>  
  2.   
  3. <head>  
  4.     <title>JSON RUN IN HTML</title>  
  5.     <script language="javascript">  
  6.         var object1 = {  
  7.             "COURSE""MCA",  
  8.             "TUTOR""Daniel Boley"  
  9.         };  
  10.         document.write("<h1>JSON with JavaScript Program</h1>");  
  11.         document.write("<br>");  
  12.         document.write("<h3>COURSE = " + object1.COURSE + "</h3>");  
  13.         document.write("<h3>TUTOR = " + object1.TUTOR + "</h3>");  
  14.         var object2 = {  
  15.             "COURSE""MBA",  
  16.             "TUTOR""JOHN KENNEDY"  
  17.         };  
  18.         document.write("<br>");  
  19.         document.write("<h3>COURSE = " + object2.COURSE + "</h3>");  
  20.         document.write("<h3>TUTOR = " + object2.TUTOR + "</h3>");  
  21.         document.write("<hr />");  
  22.         document.write(object2.COURSE + " programming language can be studied  
  23.                 " + "  
  24.                 from book written by " + object2.TUTOR);  
  25.                 document.write("<hr />");  
  26.     </script>  
  27. </head>  
  28.   
  29. <body> </body>  
  30.   
  31. </html> 
 

OUTPUT

Result

Thus, we have successfully learned an introduction to JSON.