logo

JSON Overview


Show

JSON or JavaScript Object Notation is a lightweight text-primarily based open general designed for human-readable information interchange. Conventions utilized by JSON are recognized by programmers, which consist of C, C++, Java, Python, Perl, etc.

  • It was designed for human-readable data interchange.
  • It has been extended from the JavaScript scripting language.
  • The filename extension is .json.
  • The JSON Internet Media kind is application/JSON.
  • The Uniform Type Identifier is public.json.

Uses of JSON

  • It is used even for writing JavaScript-based programs that consist of browser extensions and websites.
  • The JSON format is used for serializing and transmitting structured information over a network connection.
  • It is frequently used to transmit information among a server and web programs.
  • Web services and APIs use JSON format to offer public information.
  • It may be used with current programming languages.

Characteristics of JSON

  • JSON is simple to examine and write.
  • It is a lightweight text-based interchange format.
  • JSON is language independent.

Easy Example of JSON

The below given example below represents how to make use of JSON to store information associated with books based on their topic and edition.

{
   "book": [
      {
         "id":"01",
         "language": "Java",
         "edition": "third",
         "author": "Herbert Schildt"
      },
      {
         "id":"07",
         "language": "C++",
         "edition": "second",
         "author": "E.Balagurusamy"
      }
   ]
}

We will try some other examples. After interpretation of the above program. Let's save the code below as json.htm.

<html>
   <head>
      <title>JSON example</title>
      <script language = "javascript" >
         var object1 = { "language" : "Java", "author"  : "herbert schildt" };
         document.write("

JSON with JavaScript example

");
         document.write("
"
); document.write("

Language = "

 + object1.language+"");  
         document.write("

Author = "

 + object1.author+"");   


         var object2 = { "language" : "C++", "author"  : "E-Balagurusamy" };
         document.write("
"
); document.write("

Language = "

 + object2.language+"");  
         document.write("

Author = "

 + object2.author+"");    

         document.write("

");
         document.write(object2.language + " programming language can be studied " + "from book written by " + object2.author);
         document.write("

");
      </script>
   </head>

   <body>
   </body>
</html>

Now let's try to start json.htm using IE or any other javascript qualify browser that generates the below-given result:

You can refer to the JSON Objects chapter for more information on JSON objects.