- 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?
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
- 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:
Corresponding XML is:
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 doesn’t use end tag
- JSON is shorter
- JSON is quicker to read and write
- JSON can use arrays
- 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
We should use JASON because JSON is faster and easier than XML for AJAX applications.
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 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.