Skip to content
Justice Tech School

JSON and CSV

The json module converts dicts to text and back. csv reads and writes rows. Both are in the standard library.

Example
import json, csv, io
d = {"a": [1, 2]}
s = json.dumps(d)
print(s, json.loads(s))
out = io.StringIO()
w = csv.writer(out); w.writerow(["x", "y"]); w.writerow([1, 2])
print(out.getvalue().strip())

Result

{"a": [1, 2]} {'a': [1, 2]}
x,y
1,2

Exercise

Text to object.

json.(s)

Quiz Test

Which makes a JSON string?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.