Many source systems still hand data over as CSV, plain text that every tool can write. The first step plays the part of a nightly export, writing the JSON catalog as CSV with Python's standard csv module:
# Step 1: export BookNest's catalog as CSV, the way many source systems hand data over.
import csv, json
books = json.load(open("books.json"))["books"]
fields = ["id", "title", "author", "genre", "price", "pages", "year", "inStock"]
with open("books.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["id", "title", "author", "genre", "price", "pages", "year", "in_stock"])
for b in books:
writer.writerow([b[k] for k in fields])
print(open("books.csv", encoding="utf-8").read(), end="")Output
id,title,author,genre,price,pages,year,in_stock 1,The Quiet Harbor,Mara Ellison,Fiction,14.99,312,2024,True 2,Patterns of the Deep Web,Tomas Reyes,Technology,39.5,428,2025,True 3,Salt and Saffron,Priya Nair,Cooking,24.0,256,2023,False 4,Small Steps to Big Summits,Jonas Berg,Travel,18.75,198,2026,True 5,The Clockmaker's Paradox,Elena Sokolova,Science Fiction,16.2,344,2025,True 6,Gardens in Glass,Aiko Tanaka,Home and Garden,21.3,176,2024,True
Look at what the file has already lost. CSV has no types, so 39.5 and True are just characters, and nothing says that price is money with two decimals or that in_stock is a Boolean. Python wrote its own spellings (True, 24.0); another exporter might write true, 1 or 24,00. Every consumer must guess, and CSV Done Right shows how those guesses break pipelines. The next step makes the types explicit, once.