What is JSON

Introduction

 
JSON is the JavaScript Object Notation. It is a lightweight format for data interchange.
 
In the old days, web services use XML as a primary data transmission medium with all other applications.
 
But JSON is a more lightweight and efficient medium for data transmission compared to XML.
 
The following is the basis syntax of JSON:
 
/Syntax for Json
  1. var emp=   {"EmpName":"Chandradev"    
  2.                  ,    
  3.                  "EmpCode":"3007"    
  4.                }   
JSON process
  1. {"employees":[    
  2.     {"firstName":"Chandradev""lastName":"Sah"},     
  3.     {"firstName":"Rajan""lastName":"Prasad"},    
  4.     {"firstName":"Suraj""lastName":"Kumar"}    
  5. ]}   
Using JSON in JavaScript
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>    
  2.     
  3. <!DOCTYPE html>    
  4.     
  5. <html xmlns="http://www.w3.org/1999/xhtml">    
  6. <head runat="server">    
  7.     <title></title>    
  8.     <script type="text/javascript">    
  9.      var emp=   {"EmpName":"Chandradev"    
  10.                  ,    
  11.                  "EmpCode":"3007"    
  12.                }    
  13.     
  14.      alert(emp.EmpCode);    
  15.      alert(emp.EmpName);    
  16.     
  17.     </script>    
  18.     
  19. </head>    
  20. <body>    
  21.     <form id="form1" runat="server">    
  22.     <div>    
  23.         
  24.     </div>    
  25.     </form>    
  26. </body>    
  27. </html>   
local host
 

Advantages of JSON

  1. JSON is easier to use the alternative of XML
     
  2. JSON is a simple data exchange pattern that helps to communicate between JavaScript and server-side technology such as ASP.Net, PHP, JSP, CGI and so on
     
  3. JSON is a lightweight data-interchange format
     
  4. JSON is language independent
     
  5. JSON is "self-describing" and easy to understand
In the .Net world, we can also expose JSON data to the outside using WCF, ASP.Net, and MVC. I will be writing an article on this topic very soon.


Similar Articles