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:
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. <head>
  3. <title>JSON RUN IN HTML</title>
  4. <script language="javascript">
  5. var object1 = {
  6. "COURSE": "MCA",
  7. "TUTOR": "Daniel Boley"
  8. };
  9. document.write("<h1>JSON with JavaScript Program</h1>");
  10. document.write("<br>");
  11. document.write("<h3>COURSE = " + object1.COURSE + "</h3>");
  12. document.write("<h3>TUTOR = " + object1.TUTOR + "</h3>");
  13. var object2 = {
  14. "COURSE": "MBA",
  15. "TUTOR": "JOHN KENNEDY"
  16. };
  17. document.write("<br>");
  18. document.write("<h3>COURSE = " + object2.COURSE + "</h3>");
  19. document.write("<h3>TUTOR = " + object2.TUTOR + "</h3>");
  20. document.write("<hr />");
  21. document.write(object2.COURSE + " programming language can be studied
  22. " + "
  23. from book written by " + object2.TUTOR);
  24. document.write("<hr />");
  25. </script>
  26. </head>
  27. <body> </body>
  28. </html>

OUTPUT

Result

Thus, we have successfully learned an introduction to JSON.