Skip to course content
Free course

Python Foundations / Module 7 / Applied Checkpoint: Convert CSV to Validated JSON

Module 7 lesson

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 available or planned.

Required outputs

Write these to a separate output folder:

  • accepted_courses.json containing validated records;
  • rejected_courses.json containing source row, safe code, and all reasons;
  • transformation_log.json containing 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 ValueError without publishing outputs.

Self-review rubric

CriterionNot yetMeets
PathsPersonal or manually joined paths are embeddedPath builds portable source and output locations
ParsingCSV is split manuallycsv.DictReader and json handle structured data
ValidationMalformed rows stop all work or pass silentlyAccepted and rejected rows follow explicit rules
Source safetySource is opened for writing or changesSource bytes and checksum remain unchanged
ProvenanceOutputs cannot be traced to rules and inputLog records source, checksum, rules, counts, and outputs
FailuresMissing or malformed files create partial successExpected file failures are clear and publish no completed outputs
TestsOnly the happy path is triedSuccess, values, parsing, preservation, paths, and file failures pass