What is JSON ? Where it is used ? (For Beginners) ( From Level Zero to One) (60 seconds read)

There are multiple formats in which data is being shared or interchanged between the applications and JSON is one of them.
JSON (JavaScript Object Notation) is the data-interchange format, which is popular due to its features likes:
  • Light size
  • Portable
  • Good readability.
  • Standardization
  • Fast execution.
  • Programming language independent
JSON is one of the most popular among modern web application and data storage platforms.

Other popular data-interchange formats are : 
  • XML (Extensible Markup Language)
  • YAML (YAML Ain't Markup Language)
  • CSV (Comma-separated values)

Programming Language Independent : 
JSON can be used with any programing language it is not restricted the only JavaScript
However, in JavaScript, we don't need to import or install any package to use JSON and in other programming languages, we might need to import a package or a module to use the JSON.

Syntax and Rules

5 key points in JSON are:

1Key and ValueData to be stored in form of Key-value pairs.
2Colon signKey and Values are separted by ":" (colon sign).
3JSON ObjectCurly ({,}) braces are used to represent a JSON Object
4JSON ArraySquare brackets ([,]) are used to represent the JSON Array.
5Dot NotationThe value in JSON can be fetched by using the '.' (dot symbol).
6JSON objects and JSON arrays can be nested within each other.

Data types in JSON :

The value in the JSON must be one of the following data types:
NumberStringBoolean
JSON ObjectJSON ArrayNull

Examples


1.Simple JSON Object: 

{' car ': 'Jaguar F-PACE'}

2.Nested JSON Object and Array

data = {'company':'Boeing','details':[{'product':'Chinook','origin':'USA'}]}
data.company // result will be 'Boeing' 
data.details[0].product // result will be 'Chinook'

JSON parse() and JSON stringify()

When data is send to the server it is preferred to convert it into the string format.
  • JSON.stringify()  : Used to convert JSON Object into JSON string.
  • JSON.parse()      : Used to convert JSON string into JSON Object