Level 2 / Project 12 - CSV to JSON Converter¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 40 minutes
Focus¶
- format conversion and schema checks
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-2/12-csv-to-json-converter
python project.py data/sample_input.txt --pretty
python project.py data/sample_input.txt --format columns
python project.py data/sample_input.txt --no-types
python project.py data/sample_input.txt --output data/output.json
pytest -q
Expected terminal output¶
Expected artifacts¶
- JSON output on stdout or file
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--columnsflag to select only specific columns:--columns name,age. - Add row-count validation — log rows with mismatched column counts.
- Add a
--schemaoutput that shows detected types per column.
Break it (required) — Core¶
- Feed a CSV with quoted fields containing commas (e.g.
"Smith, Jr"). - Feed a file with inconsistent column counts per row.
- Feed a value like
"123abc"— does type inference misfire?
Fix it (required) — Core¶
- Add basic quoted-field handling for CSV values.
- Pad short rows and truncate long rows to match header length.
- Ensure
infer_typeonly converts when the entire value is numeric.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why does type inference try int before float?
- What is the difference between "array of objects" and "columnar" JSON formats?
- How does
zip(headers, values)elegantly build record dicts? - When would you choose JSON over CSV for data storage?
Mastery check¶
You can move on when you can:
- explain how zip pairs two lists element-by-element,
- implement type inference logic from memory,
- convert between objects and columnar JSON formats,
- describe edge cases in CSV parsing (quotes, escapes, encodings).
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|