JSON and CSV Handling
JSON और CSV Handling
What is JSON and CSV Handling?
JSON and CSV Handling means jSON and CSV are common formats for storing and exchanging structured data.
In real programs, this topic helps in reading CSV files. Learn the idea first, then type the program yourself and compare the output.
| Point | Details |
|---|---|
| Course Area | Advanced Python Professional concepts used to make code reusable, clean and project-ready. |
| Main Use | reading CSV files |
| Example File | json-csv.py |
| Practice Focus | Run, change values, and explain the output line by line. |
Why should you learn this?
- It is useful for reading CSV files.
- It connects with working with API JSON.
- It improves your ability to read, write and debug Python programs.
Important Terms
These terms are used directly in this lesson. Understand them before memorising the code.
| Term | Meaning |
|---|---|
| json | Text-based format commonly used in APIs and configuration files. |
| csv | Comma-separated format commonly used for spreadsheets. |
| dictionary | dictionary is an important term in this topic. |
| reader | Tool used to read CSV rows. |
| writer | Tool used to write CSV rows. |
Syntax / Basic Pattern
The simple pattern is: prepare data, apply the concept, then show the result.
import json
student = {"name": "Riya", "marks": 94}
json_text = json.dumps(student, indent=2)
print(json_text)
back_to_dict = json.loads(json_text)
print(back_to_dict["name"])Complete Example Program
import json
student = {"name": "Riya", "marks": 94}
json_text = json.dumps(student, indent=2)
print(json_text)
back_to_dict = json.loads(json_text)
print(back_to_dict["name"])Expected Output
Program Explanation
import jsonimports ready-made features from a module/library.student = {"name": "Riya", "marks": 94}stores a value in student.json_text = json.dumps(student, indent=2)stores a value in json_text.print(json_text)displays information or calculated result on the screen.back_to_dict = json.loads(json_text)stores a value in back_to_dict.print(back_to_dict["name"])displays information or calculated result on the screen.
Where will you use it?
- Reading csv files.
- Working with api json.
- Exporting reports.
Common Mistakes
- Making code complex when a simple function or class is enough.
- Not handling possible errors or edge cases.
- Mixing project dependencies instead of using a virtual environment.
Practice Tasks
- Type the program in
json-csv.pyand run it. - Change input values or sample data and observe the new output.
- Create one example related to reading CSV files.
- Write 5 lines explaining the logic in your own words.
Summary
JSON and CSV Handling is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.
JSON और CSV Handling क्या है?
JSON और CSV Handling ka matlab hai: JSON and CSV are common formats for storing and exchanging structured data. Simple words me, ye topic practical Python programs likhne me direct use hota hai.
Is topic ko sirf definition ke liye nahi, balki reading CSV files jaise real examples ke liye practice karein.
यह क्यों सीखना जरूरी है?
- Ye reading CSV files me kaam aata hai.
- Ye working with API JSON se bhi connected hai.
- Isse aap code ka output aur errors better samajh paate hain.
Important Terms
| Term | Meaning |
|---|---|
| json | Text-based format commonly used in APIs and configuration files. |
| csv | Comma-separated format commonly used for spreadsheets. |
| dictionary | dictionary is an important term in this topic. |
| reader | Tool used to read CSV rows. |
| writer | Tool used to write CSV rows. |
Syntax / Basic Pattern
Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.
import json
student = {"name": "Riya", "marks": 94}
json_text = json.dumps(student, indent=2)
print(json_text)
back_to_dict = json.loads(json_text)
print(back_to_dict["name"])Complete Example Program
import json
student = {"name": "Riya", "marks": 94}
json_text = json.dumps(student, indent=2)
print(json_text)
back_to_dict = json.loads(json_text)
print(back_to_dict["name"])Expected Output
Program Explanation
import jsonimports ready-made features from a module/library.student = {"name": "Riya", "marks": 94}stores a value in student.json_text = json.dumps(student, indent=2)stores a value in json_text.print(json_text)displays information or calculated result on the screen.back_to_dict = json.loads(json_text)stores a value in back_to_dict.print(back_to_dict["name"])displays information or calculated result on the screen.
Practical Uses
- Reading csv files.
- Working with api json.
- Exporting reports.
Common Mistakes
- Making code complex when a simple function or class is enough.
- Not handling possible errors or edge cases.
- Mixing project dependencies instead of using a virtual environment.
Practice Tasks
- Program ko
json-csv.pyfile me type karke run karein. - Values change karke output compare karein.
- reading CSV files par ek छोटा example banayen.
- Logic ko apne words me 5 lines me likhein.
सारांश
JSON and CSV Handling ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.