May 08, 2021 JSON
JSON: J ava S cript O bject N otation (JavaScript object notation)
JSON is the syntax for storing and exchanging text information, similar to XML.
JSON is smaller, faster, and easier to resolve than XML.
This employee object is an array of 3 employee records (objects).
To turn any JavaScript object into a JSON is to serialize the object into a string in JSON format so that it can be passed over the network to other computers.
JSON uses Javascript syntax to describe data objects, but JSON remains independent of language and platform. T he JSON parser and JSON library support many different programming languages. JSON is currently supported by a large number of dynamic (PHP, JSP, .NET) programming languages.
The JSON text format is syntaxally the same as the code that created the JavaScript object.
Because of this similarity, without parsers, JavaScript programs can use built-in eval() functions to generate native JavaScript objects from JSON data.
JSON or JavaScript object notation is a lightweight, text-based open standard designed for readable data exchange. Programs that are contracted to use JSON include C, C, Java, Python, Perl, and so on.
Given the language and version information in the book data, the following example shows the use of JSON to store book information:
{
"book": [
{
"id":"01",
"language": "Java",
"edition": "third",
"author": "Herbert Schildt"
},
{
"id":"07",
"language": "C++",
"edition": "second",
"author": "E.Balagurusamy"
}]
}
After understanding the above procedure, let's look at another example, let's save the following code as .htm:
<html>
<head>
<title>JSON example</title>
<script language="javascript" >
var object1 = { "language" : "Java", "author" : "herbert schildt" };
document.write("<h1>JSON with JavaScript example</h1>");
document.write("<br>");
document.write("<h3>Language = " + object1.language+"</h3>");
document.write("<h3>Author = " + object1.author+"</h3>");
var object2 = { "language" : "C++", "author" : "E-Balagurusamy" };
document.write("<br>");
document.write("<h3>Language = " + object2.language+"</h3>");
document.write("<h3>Author = " + object2.author+"</h3>");
document.write("<hr />");
document.write(object2.language + " programming language can be studied " +
"from book written by " + object2.author);
document.write("<hr />");
</script>
</head>
<body>
</body>
</html>
Now try opening this page with IE or any other JavaScript-enabled browser, and it will produce the following results:
You can refer to the JSON object to learn more about the JSON object.