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:
Other popular data-interchange formats are :
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.
1.Simple JSON Object:
2.Nested JSON Object and Array
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 (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
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:1 | Key and Value | Data to be stored in form of Key-value pairs. |
2 | Colon sign | Key and Values are separted by ":" (colon sign). |
3 | JSON Object | Curly ({,}) braces are used to represent a JSON Object |
4 | JSON Array | Square brackets ([,]) are used to represent the JSON Array. |
5 | Dot Notation | The value in JSON can be fetched by using the '.' (dot symbol). |
6 | JSON 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:Number | String | Boolean |
JSON Object | JSON Array | Null |
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