|
2 | 2 |
|
3 | 3 | ## What is JSON?
|
4 | 4 |
|
5 |
| -- <a href="https://www.json.org/json-en.html">JSON (JavaScript Object Notation)</a> is a format for structuring data. |
| 5 | +- [JSON]("https://www.json.org/json-en.html") (JavaScript Object Notation) is a format for structuring data. |
6 | 6 | - JSON is a lightweight, text-based data interchange format that is completely language-independent.
|
7 | 7 | - Similar to XML, JSON is a format for structuring data commonly used by web applications to communicate with each other.
|
8 | 8 |
|
|
14 | 14 | age = 21
|
15 | 15 | ```
|
16 | 16 |
|
17 |
| -- When we use `age`, it gets replaced with `21`. However, <i>age doesn't contain 21, it contains the address of the memory location where 21 is stored</i>. |
| 17 | +- When we use `age`, it gets replaced with `21`. However, *age doesn't contain 21, it contains the address of the memory location where 21 is stored*. |
18 | 18 |
|
19 | 19 | - While this works locally, transferring this data, such as through an API, poses a challenge. Sending your computer’s entire memory with the addresses is impractical and insecure. This is where JSON comes to the rescue.
|
20 | 20 |
|
@@ -67,7 +67,7 @@ print(students_dict['name'])
|
67 | 67 | - Ouput:
|
68 | 68 |
|
69 | 69 | ```json
|
70 |
| -{'id': '01', 'name': 'Yatharth', 'department': 'Computer Science Engineering'} |
| 70 | +{"id": "01", "name": "Yatharth", "department": "Computer Science Engineering"} |
71 | 71 | Yatharth
|
72 | 72 | ```
|
73 | 73 |
|
@@ -114,16 +114,15 @@ f.close()
|
114 | 114 | - Ouput
|
115 | 115 |
|
116 | 116 | ```json
|
117 |
| -{'id': '01', 'name': 'Yatharth', 'department': 'Computer Science Engineering'} |
118 |
| -{'id': '02', 'name': 'Raj', 'department': 'Mechanical Engineering'} |
| 117 | +{"id": "01", "name": "Yatharth", "department": "Computer Science Engineering"} |
| 118 | +{"id": "02", "name": "Raj", "department": "Mechanical Engineering"} |
119 | 119 | ```
|
120 | 120 | - `json.load()`: Reads JSON data from a file object and deserializes it into a Python object.
|
121 | 121 | - `json.loads()`: Deserializes JSON data from a string into a Python object.
|
122 |
| -<hr> |
123 | 122 |
|
124 |
| -### Addtiotnal Context |
| 123 | + |
| 124 | +## Addtiotnal Context |
125 | 125 | Relation between python data types and json data types is given in table below.
|
126 |
| -</br> |
127 | 126 |
|
128 | 127 | | Python Object | JSON Object |
|
129 | 128 | |-----------------|-------------|
|
@@ -288,7 +287,4 @@ write_json(y)
|
288 | 287 | }
|
289 | 288 | ```
|
290 | 289 |
|
291 |
| -</br> |
292 |
| -<hr> |
293 |
| - |
294 | 290 | The Python json module simplifies the handling of JSON data, offering a bridge between Python data structures and JSON representations, vital for data exchange and storage in modern applications.
|
0 commit comments