Project

Validate the Recruits

New apprentices sign up through a form that saves nested JSON. Some entries are… creative. Your job: check each record and explain exactly what's wrong, so a human can fix it.

A good validator never crashes on bad data. Use dict.get() with a default to walk nested structures safely:

rec = {"name": "Ada"}
rec.get("skills", {}).get("python")   # None, no KeyError

Assignment

validate(rec) returns a list of error strings, in this order, for each rule that fails (an empty list means the record is valid):

  1. "name: missing": name is absent or blank after stripping.
  2. "email: invalid": email must fully match EMAIL_RE.
  3. "joined: invalid": joined must parse as %Y-%m-%d.
  4. "level: invalid": rec["skills"]["python"] must be an int from 1 to 5 (it may be missing at any depth).

Then problems(json_text) loads {"recruits": [...]} and returns a dict mapping each invalid record's position (0-based index) to its error list.