File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments