🟡 Advanced Python  ·  Lesson 25

JSON और CSV Handling

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

TermMeaning
jsonText-based format commonly used in APIs and configuration files.
csvComma-separated format commonly used for spreadsheets.
dictionarydictionary is an important term in this topic.
readerTool used to read CSV rows.
writerTool used to write CSV rows.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
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

Python – json-csv.py
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

{ "name": "Riya", "marks": 94 } Riya

Program Explanation

  • import json imports 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

  1. Program ko json-csv.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. reading CSV files par ek छोटा example banayen.
  4. 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.

← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.