JSON
- JSON stands for JavaScript Object Notation
- JSON is a lightweight data exchange format
- JSON is a text format for storing and transporting data
- JSON is self-describing and easy to understand
- JSON data can be hierarchical
Syntax
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
Data Types
In JSON, values must be one of the following data types:
- string
- number
- object
- array
- boolean
- null
Files
- The file type for JSON files is
.json
- The MIME (Multipurpose Internet Mail Extensions) type for JSON text is
application/json
Using in JavaScript
- JSON makes it possible to store and send JavaScript objects as text.
Parsing JSON
Convert JSON to JavaScript Object
const data = '{"name": "ganesh", "country": "india", skills: ["html", "css", "js"]}';
const person = JSON.parse(data)
Stringify
Convert JavaScript Object to JSON
const person = {
name: "ganesh",
country: "india"
}
const data = JSON.stringify(obj)