Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Introduction to the JSON tutorial


May 08, 2021 JSON


Table of contents


A guided tour of the JSON tutorial

Before we get to know JSON, let's understand what JSON is!


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.

JSON instance

{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}

This employee object is an array of 3 employee records (objects).


What is JSON?

  • JSON refers to JavaScript object notation (J ava S cript O bject N otation)
  • JSON is a lightweight text data exchange format
  • JSON is independent of language *
  • JSON is self-describing and easier to understand

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.


JSON - Converts to JavaScript objects

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.

Introduction to Json

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.

  • JSON is an abbreviation for JavaScript Object Notation.
  • This format was proposed by Douglas Crockford.
  • Designed for readable data exchange.
  • It evolved from the JavaScript scripting language.
  • The file name extension is .json.
  • JSON's network media type is application/json.
  • Uniform Type Identifier is public.json.

JSON range of use

  • Used to write JavaScript-based applications, including browser extensions and websites.
  • The JSON format can be used to serialize and transfer structured data over a network connection.
  • Primarily used to transfer data between servers and Web applications.
  • Web services and APIs can use the JSON format to provide public data.
  • It can also be used in modern programming languages.

JSON features

  • JSON is easy to read and write.
  • It is a lightweight text-based exchange format.
  • Language is irrelevant.

A simple example of JSON

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:

Introduction to the JSON tutorial

You can refer to the JSON object to learn more about the JSON object.