PYTHON LESSON 20 OF 32

CSV & JSON: data you can share

CSV represents tables of text rows. JSON represents structured objects, lists and primitive values. Use csv and json modules instead of splitting CSV by commas yourself: quoted fields may contain commas.

हिन्दी में समझें

CSV तालिका की पंक्तियाँ और JSON संरचित डेटा रखता है। csv और json मॉड्यूल लें। CSV को सिर्फ कॉमा से न तोड़ें, क्योंकि उद्धरण के अंदर भी कॉमा हो सकता है।

अभ्यास: JSON में points को 50 करें और प्रिंट करें।

Hinglish mein samjhein

CSV table rows aur JSON structured data rakhta hai. csv aur json modules use karo. CSV ko sirf comma se split mat karo; quoted values mein comma ho sakta hai.

Practice: JSON points 50 karo aur print karo.

A small Python example

import json
text = '{"name": "Asha", "points": 25}'
player = json.loads(text)
print(player["points"])

The browser playground runs real Python with Pyodide. Use sample variables instead of interactive input(). Browser package support differs from desktop Python.

Try this example in the Python playground →

Practise this idea

Change the JSON points value to 50 and print it.

Check answer & explanation
import json
text = '{"name": "Asha", "points": 50}'
player = json.loads(text)
print(player["points"])

json.loads reads the numeric JSON value into the dictionary. Updating the sample JSON to 50 changes the parsed points.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

What converts JSON text to Python data?

  1. json.loads()
  2. json.dumps()
  3. json.print()
Check the quiz answer

json.loads()

loads() reads JSON text; dumps() creates JSON text.

References & corrections

Use the official Python documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.