The stdlib json and csv modules parse common interchange formats—no pip install. JSON maps to Python dicts/lists; CSV suits tabular exports from spreadsheets and logs.
JSON
import json
data = {"name": "Ada", "scores": [10, 20]}
text = json.dumps(data, indent=2)
parsed = json.loads(text)
CSV
import csv, io
output = io.StringIO()
writer = csv.writer(output)
writer.writerow(["name", "score"])
writer.writerow(["Ada", 99])
print(output.getvalue())
Important interview questions and answers
- Q: JSON types in Python?
A: object→dict, array→list, string→str, number→int/float, true/false→bool, null→None. - Q: csv module vs pandas?
A: csv is stdlib for simple files; pandas (PyPI) adds DataFrame analytics—install locally for data science.
Self-check
- What function parses a JSON string?
- What module writes CSV rows?
Tip: json.loads returns Python types—validate untrusted JSON before use in apps.
Interview prep
- JSON to Python types?
object→dict, array→list, string→str, number→int/float, true/false→bool, null→None.
- csv vs pandas?
csv stdlib for simple files; pandas DataFrame analytics require local pip install.