ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,jQuery Plugins,jQuery UI,SSRS,XML,HTML,jQuery demos,code snippet examples.

Breaking News

  1. Home
  2. XML
  3. What is JSON?

What is JSON?

JSON is a text-based data exchange format that enables us to quickly and easily share information between all of our systems and devices. Like most famous XML, it is platform independent and human readable. This article explains JSON (JavaScript Object Notification), its relationship to JavaScript, and the difference between JSON and XML. This is an introduction to JSON. Summary of the article:
  • What is JSON?
  • History of JSON
  • Characteristics of JSON
  • Syntax of JSON
  • Example of JSON
  • JSON VS XML
  • Why JSON?
  • JSON File
  • JSON Data Types
What is JSON?
Full meaning of JSON is JavaScript Object Notation. JSON is a lightweight syntax/format for storing and exchanging data. It is cross platform and language independent. It is self-describing and easy to understand. It is easy for human to read and write and for machines to parse and generate. As an alternative to XML it is primarily used to transmit data between a server and web application. JSON is based on the JavaScript language. But, it does not require JavaScript to read or write because it is a text format that is language independent.
JOSON and XML have some similarities:
  • Both JSON and XML is plain text
  • Both JSON and XML is self-describing /human readable
  • Both JSON and XML is hierarchical (values within values)
  • Both JSON and XML can be fetched with an HTTP Request
History of JSON
JSON was first introduced by Douglas Crockford.
Characteristics of JSON
The characteristics of JSON are given bellow:
  • It is easy to read and write
  • It is lightweight text based exchange format
  • It is language independent
Syntax of JSON
SON basic syntax is a subset of the JavaScript object notation syntax, it includes the following:
  • The data structures are based on key/value pairs
    Key: A key is a string and enclosed in quotation marks
    Value: A value can be a string, number, array, boolean expression, or object
  • Curly brackets or braces represent objects and every name are followed by colon (:), the name/value pairs are separated by comma (,)
  • Square brackets represent arrays and values are separated by comma (,)
    “title” : “ABC Company”
Example of JSON
An example of JSON data is given bellow:
{
    "Students": {
        "Student": [
            {
                "FirstName": "St.",
                "LastName": "John"
            },
            {
                "FirstName": "Adam",
                "LastName": "Smith"
            },
            {
                "FirstName": "Jim",
                "LastName": "Katman"
            }
        ]
    }
}
Corresponding XML is:
<Students>
  <Student>
    <FirstName>St.</FirstName>
    <LastName>John</LastName>
  </Student>
  <Student>
    <FirstName>Adam</FirstName>
    <LastName>Smith</LastName>
  </Student>
  <Student>
    <FirstName>Jim</FirstName>
    <LastName>Katman</LastName>
  </Student>
</Students>
JSON VS XML
The JSON and XML are not exactly same. There exists some difference between them. The difference between JSON and XML is given bellow:
JSON:
  • JSON can be parsed by a standard JavaScript function
  • JSON doesn’t use end tag
  • JSON is shorter
  • JSON is quicker to read and write
  • JSON can use arrays
XML:
  • XML has to be parsed with an XML parser
  • XML doesn’t use end tag
  • XML is not shorter
  • XML is not quicker to read and write
  • XML cannot use arrays
Why JSON?
We should use JASON because JSON is faster and easier than XML for AJAX applications.
JSON File
The extension of JSON file is “.json”.
Internet media/MIME type for JSON text is “application/json”.
JSON Data Types
JSON values can be:
  • Number- integer or floating point
  • String- in double quotes
  • Boolean- true or false
  • Array- in square brackets
  • Object- in curly braces
  • null- empty value
Uses of JSON
JSON is used in numerous ways. Some of them are given bellow:
  • It is primarily used to transmit data between server and web application
  • It is used in JavaScript based application which includes browser extension and websites
  • It is used for serializing & transmitting structured data over network connection
  • It is used in Web Services and API’s to provide public data
  • It is used with many programming languages
JSON has some limitations. It does not support binary values. Its only support text, numeric values, and Boolean values. Binary values are not supported.

No comments