Applied Checkpoint: Convert CSV to Validated JSON
Unit ID: M07-U07 Estimated active time: 50-70 minutes
Supplied source
Use data/source_courses.csv. It contains five fictional rows. Do not edit or overwrite it.
Required headers:
code,title,hours,status
Validation rules
- code: non-empty text after trimming, output uppercase;
- title: non-empty text after trimming;
- hours: integer text converted to an integer from 0 through 40;
- status: cleaned lowercase value
availableorplanned.
Required outputs
Write these to a separate output folder:
accepted_courses.jsoncontaining validated records;rejected_courses.jsoncontaining source row, safe code, and all reasons;transformation_log.jsoncontaining source name, SHA-256, rules, row counts, and output names.
Required functions
Create functions for source validation, CSV reading, row validation, JSON writing, checksum calculation, and orchestration. Use Path, csv, json, and hashlib from the standard library.
Expected outcome
- Source data rows:
5 - Accepted rows:
3 - Rejected rows:
2 - Accepted codes:
AI-01,PY-01,ML-01 - Accepted hours total:
80 - Source checksum unchanged after conversion
Required tests
Use a temporary folder to test:
- successful conversion;
- exact accepted values and rejected count;
- JSON files parse successfully;
- source bytes remain unchanged;
- output paths differ from source;
- missing source raises
FileNotFoundError; - wrong suffix raises
ValueError; and - missing required header raises
ValueErrorwithout publishing outputs.
Self-review rubric
| Criterion | Not yet | Meets |
|---|---|---|
| Paths | Personal or manually joined paths are embedded | Path builds portable source and output locations |
| Parsing | CSV is split manually | csv.DictReader and json handle structured data |
| Validation | Malformed rows stop all work or pass silently | Accepted and rejected rows follow explicit rules |
| Source safety | Source is opened for writing or changes | Source bytes and checksum remain unchanged |
| Provenance | Outputs cannot be traced to rules and input | Log records source, checksum, rules, counts, and outputs |
| Failures | Missing or malformed files create partial success | Expected file failures are clear and publish no completed outputs |
| Tests | Only the happy path is tried | Success, values, parsing, preservation, paths, and file failures pass |
