python
from voluptuous import Schema, Required, Length, Range
person_schema = Schema({
Required('name'): str,
Required('age'): int,
'email': str,
'address': {
'street': str,
'city': str,
'zipcode': str
}
})
person_data = {
'name': 'Alice',
'age': 30,
'email': 'alice@example.com',
'address': {
'street': '123 Main St',
'city': 'New York',
'zipcode': '10001'
}
}
validated_data = person_schema(person_data)
python
person_schema = Schema({
Required('name'): All(str, Length(min=2, max=50)),
Required('age'): All(int, Range(min=18, max=65))
})