Validating the Required Fields

field validation

Part of: Structured JSON Extractor

The JSON parsed. That only means it was well-formed, not that it was correct . The extractor's real job is a contract: every required field present, and each value the right type. Parsing checks syntax. Validation checks meaning. This lesson is the spine of the whole tool. Parsing success is not correctness json.loads happily accepts {"name": "Ada"} even when your schema demands name, email, and phone. It accepts {"amount": "fifty"} when amount should be a number. The JSON is fine. The data is wrong. You have to check it yourself. Two checks: presence and type Presence first: a required key that's absent or null is a missing error. Then type: a present value that isn't the expected Python type is a wrong type error. An empty error list means the record is valid. Normalize while you're here Extraction output should be predictable. When an optional field is absent, set it to None explicitly rather than leaving the key off, so every record has the same keys: Now downstream code can write record["phone"] without a KeyError, whether the phone was found or not. Why this is the product An extractor without validation is a guess with extra steps. What matters is that you can prove the retu

Challenge: Validate Against the Schema