← Python Programming
Files, errors and data · 15 MIN

Working with JSON and CSV

Working with JSON and CSV

The json module converts between Python values and JSON. The csv module handles delimiter-separated tabular data. Use newline="" when opening CSV files for writing and choose a clear encoding. Validate external data before using it.

Try it yourself

Change the example, run it, and explain the result in your own words. Then create one variation of your own.

Key idea

Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.

Code example

import json
record = {"name": "Ada", "active": True}
text = json.dumps(record)
print(json.loads(text)["name"])