Skip to content

Commit fcf50b2

Browse files
feat: add json object
1 parent 3238b5f commit fcf50b2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

part1 (Basics)/12_json.object.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
INFO: What is JSON ?
3+
JSON stands for JavaScript Object Notation.
4+
It's a lightweight data format used to store and exchange data, expecially between a client & a server.
5+
Although it originates from JavaScript, JSON is language-independent and is supported across all major programming languages.
6+
*/
7+
8+
/*
9+
INFO: Use Cases of JSON
10+
1. Sending and receving data from APIS
11+
2. Storing data in localStorage or sessionStorage
12+
3. Configuration files (e.g., package.json)
13+
4. Server communication via fetch or AJAX
14+
*/
15+
16+
// INFO: Common JSON Methods
17+
18+
/*
19+
INFO: JSON.stringify()
20+
Converts a javascript object to a json string.
21+
*/
22+
const user = {
23+
name: "Rafay",
24+
age: 25,
25+
isAdmin: false,
26+
};
27+
28+
const jsonString = JSON.stringify(user);
29+
console.log(jsonString);
30+
31+
/*
32+
INFO: JSON.parse()
33+
Converts a JSON string into a javascript object.
34+
*/
35+
const jsonStr = '{"name": "Rafay", "age": 25}';
36+
const parsed = json.parse(jsonStr);
37+
console.log(parsed.name);
38+
39+
40+
41+
42+

0 commit comments

Comments
 (0)