🎓 EASYTUTORGUIDE · Complete Python Course

Very beginner → professional Python · 60 chapters · 900 topics

EasyTutorGuide

Chapter 28: CSV, JSON and Structured Data

Complete Python lesson for very beginners. Technical words are explained in simple language, and every outline topic includes a practical example, expected output, steps, and practice.

Python CourseVery Beginner Friendly15 TopicsExamples + Output20 Q&A
Chapter 28 · 15 topics
100%

Chapter Overview

This Python tutorial chapter covers CSV, JSON and Structured Data through 15 connected topics. Work through the examples in order, check the expected output, and complete the practice after each topic.

  • 28.1 CSV Format
  • 28.2 Reading CSV
  • 28.3 Writing CSV
  • 28.4 CSV Dictionaries
  • 28.5 JSON Format
  • Plus 10 additional Python topics in this chapter.

28.1 CSV Format

CSV Format is part of CSV, JSON and Structured Data. In simple language, it means a simple text format for rows and columns.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: CSV Format (a simple text format for rows and columns).

Python / Practical Example

import csv
from io import StringIO
buffer = StringIO()
writer = csv.writer(buffer)
writer.writerow(["name", "score"])
print(buffer.getvalue().strip())

Expected Output

name,score

Step-by-Step Explanation

  1. Create an in-memory text buffer.
  2. csv.writer formats a row using CSV rules.
  3. strip() removes the final newline for display.
Practice: Re-type the example for “CSV Format”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.2 Reading CSV

Reading CSV is part of CSV, JSON and Structured Data. In simple language, it means a simple text format for rows and columns.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Reading CSV (a simple text format for rows and columns).

Python / Practical Example

import csv
from io import StringIO
buffer = StringIO()
writer = csv.writer(buffer)
writer.writerow(["name", "score"])
print(buffer.getvalue().strip())

Expected Output

name,score

Step-by-Step Explanation

  1. Create an in-memory text buffer.
  2. csv.writer formats a row using CSV rules.
  3. strip() removes the final newline for display.
Practice: Re-type the example for “Reading CSV”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.3 Writing CSV

Writing CSV is part of CSV, JSON and Structured Data. In simple language, it means a simple text format for rows and columns.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Writing CSV (a simple text format for rows and columns).

Python / Practical Example

import csv
from io import StringIO
buffer = StringIO()
writer = csv.writer(buffer)
writer.writerow(["name", "score"])
print(buffer.getvalue().strip())

Expected Output

name,score

Step-by-Step Explanation

  1. Create an in-memory text buffer.
  2. csv.writer formats a row using CSV rules.
  3. strip() removes the final newline for display.
Practice: Re-type the example for “Writing CSV”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.4 CSV Dictionaries

CSV Dictionaries is part of CSV, JSON and Structured Data. In simple language, it means a simple text format for rows and columns.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: CSV Dictionaries (a simple text format for rows and columns).

Python / Practical Example

import csv
from io import StringIO
buffer = StringIO()
writer = csv.writer(buffer)
writer.writerow(["name", "score"])
print(buffer.getvalue().strip())

Expected Output

name,score

Step-by-Step Explanation

  1. Create an in-memory text buffer.
  2. csv.writer formats a row using CSV rules.
  3. strip() removes the final newline for display.
Practice: Re-type the example for “CSV Dictionaries”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.5 JSON Format

JSON Format is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: JSON Format (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “JSON Format”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.6 JSON Objects

JSON Objects is part of CSV, JSON and Structured Data. In simple language, it means a value with data and behavior.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: JSON Objects (a value with data and behavior).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “JSON Objects”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.7 JSON Arrays

JSON Arrays is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: JSON Arrays (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “JSON Arrays”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.8 json.loads()

json.loads() is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: json.loads() (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “json.loads()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.9 json.dumps()

json.dumps() is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: json.dumps() (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “json.dumps()”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.10 Reading JSON Files

Reading JSON Files is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Reading JSON Files (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “Reading JSON Files”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.11 Writing JSON Files

Writing JSON Files is part of CSV, JSON and Structured Data. In simple language, it means a text format for structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Writing JSON Files (a text format for structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “Writing JSON Files”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.12 Serialization

Serialization is part of CSV, JSON and Structured Data. In simple language, it means a Python idea used while learning csv, json and structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Serialization (a Python idea used while learning csv, json and structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “Serialization”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.13 Deserialization

Deserialization is part of CSV, JSON and Structured Data. In simple language, it means a Python idea used while learning csv, json and structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Deserialization (a Python idea used while learning csv, json and structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “Deserialization”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.14 Custom Serialization

Custom Serialization is part of CSV, JSON and Structured Data. In simple language, it means a Python idea used while learning csv, json and structured data.

It is one building block of csv, json and structured data and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Custom Serialization (a Python idea used while learning csv, json and structured data).

Python / Practical Example

import json
data = {"name": "Ava", "score": 92}
text = json.dumps(data, sort_keys=True)
print(text)
print(json.loads(text)["score"])

Expected Output

{"name": "Ava", "score": 92}
92

Step-by-Step Explanation

  1. json.dumps() serializes Python data to JSON text.
  2. json.loads() parses JSON text back into Python data.
  3. Use safe formats and validate untrusted input.
Practice: Re-type the example for “Custom Serialization”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

28.15 Data Conversion Projects

Data Conversion Projects is part of CSV, JSON and Structured Data. In simple language, it means a Python idea used while learning csv, json and structured data.

It helps you prepare a reliable Python workspace so the same commands and files run in the environment you expect. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Data Conversion Projects (a Python idea used while learning csv, json and structured data).

Python / Practical Example

text = "42"
number = int(text)
print(number + 8)
print(str(number))

Expected Output

50
42

Step-by-Step Explanation

  1. Start with text.
  2. int() converts compatible text to an integer.
  3. str() can convert a value back to text.
Practice: Re-type the example for “Data Conversion Projects”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

Common Beginner Mistakes

  • Copying code without predicting what each line does.
  • Ignoring the first useful error message or traceback location.
  • Mixing tabs/spaces or changing indentation accidentally.
  • Using data of the wrong type for an operation.
  • Trying to learn many advanced variations before mastering one small working example.

Chapter Practice

  1. Choose three topics from this chapter and re-type their examples without copying and pasting.
  2. For each example, change one input and predict the output first.
  3. Explain five technical terms from this chapter in your own beginner-friendly words.
  4. Create one small program that combines at least two chapter topics.
  5. Keep notes about errors you made and what fixed them.

Mini Project / Challenge

Create a small Python exercise that combines at least three ideas from CSV, JSON and Structured Data. Start with a tiny working version, test it, then improve it one step at a time.

  1. Choose three topics from this chapter.
  2. Write or adapt a small Python example using those topics.
  3. Predict the output before running the code.
  4. Test at least one different input.
  5. Write two sentences explaining what the program does and what you learned.

20 Questions & Answers

1. What is the main goal of Chapter 28?

The goal is to understand csv, json and structured data through small explanations, examples, and practice.

2. Should I memorize every command or method?

No. Understand the pattern, practice the common form, and learn how to read documentation when you need exact details.

3. Why are the examples small?

Small examples isolate one idea at a time, which makes errors easier to understand and fix.

4. What should I do when an example gives an error?

Read the last part of the traceback, check spelling and indentation, confirm the required package or file exists, and compare the input types with what the operation expects.

5. Why should I predict output before running code?

Prediction forces you to reason about the program instead of only copying it.

6. What should I remember about CSV Format?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

7. What should I remember about Reading CSV?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

8. What should I remember about Writing CSV?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

9. What should I remember about CSV Dictionaries?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

10. What should I remember about JSON Format?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

11. What should I remember about JSON Objects?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

12. What should I remember about JSON Arrays?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

13. What should I remember about json.loads()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

14. What should I remember about json.dumps()?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

15. What should I remember about Reading JSON Files?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

16. What should I remember about Writing JSON Files?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

17. What should I remember about Serialization?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

18. What should I remember about Deserialization?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

19. What should I remember about Custom Serialization?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

20. What should I remember about Data Conversion Projects?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.