JSON Validation

Learn more about the concept of JSON schema and its validation.

We'll cover the following...

Overview

We noted that our mypy type hint doesn’t really guarantee the JSON document is—in any way—what we expected. There is a package in the Python Package Index that can be used for this. The jsonschema package lets us provide a specification for a JSON document, and then confirm whether or not the document meets the specification.

The JSON Schema validation is a runtime check, unlike the mypy type hint. This means using validation will make our program slower. It can also help to diagnose subtly incorrect JSON documents. For details, visit https://json-schema.org. This is evolving toward standardization, and there are several versions of compliance checking available.

We’ll focus on newline-delimited ...