How do I validate dicts in Python with standard library only?

Validating dictionaries in Python can be achieved using the standard library, particularly with the `jsonschema` module provided. Here's a simple example of how to validate a dictionary against a schema.

import jsonschema from jsonschema import validate # Define a schema schema = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, }, "required": ["name", "age"] } # Define a dictionary to validate data = { "name": "John", "age": 30 } # Validate the dictionary validate(instance=data, schema=schema) print("Data is valid!")

Python dictionary validation jsonschema standard library