What is JSON?
-
JSON stands for JavaScript Object
Notation.
- Files are saved with .json extension.
Purpose:
-
JSON is a text format to show structured
data & commonly used for transmitting data in web-applications.
Pre-Requisites:
-
Basic understanding of HTML &
CSS.
-
Basic Concepts of JavaScript.
How to Write it:
-
JSON written in the form of Object
(JavaScript).
Example:
The example
defines an object with 2 properties.
1.
Name
2.
Email
Every Property has its own value.
If
You parse the JSON string with a JavaScript program. You can access the data as
an object.
let name = obj.name;
let email = obj.email;
Why Use JSON:
- It is text-only so
data can easily be sent between computers and is language independent.
- JavaScript can
easily convert JSON data into Js Object.
- JavaScript has a
built-in function for converting JSON string into JavaScript Object. {
JSON.parse() }
- JavaScript also has a built-in function to convert object to JSON String.
{ JSON.stringify() }
Storing Data:
- JSON makes it possible for us to store js objects as text.
- Let’s see how to store data :
Rules
-
Data is in name/value pairs.
-
Must be separated by commas.
-
Curly braces hold objects.
-
Square brackets hold arrays.
0 Comments