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. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script type="text/javascript">
  7. var emp= {"EmpName":"Chandradev"
  8. ,
  9. "EmpCode":"3007"
  10. }
  11. alert(emp.EmpCode);
  12. alert(emp.EmpName);
  13. </script>
  14. </head>
  15. <body>
  16. <form id="form1" runat="server">
  17. <div>
  18. </div>
  19. </form>
  20. </body>
  21. </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.