Skip to content

Instantly share code, notes, and snippets.

@junaruga
Created August 4, 2017 15:38
Show Gist options
  • Select an option

  • Save junaruga/3598ccc5cef1b3e75c10c1dad5317887 to your computer and use it in GitHub Desktop.

Select an option

Save junaruga/3598ccc5cef1b3e75c10c1dad5317887 to your computer and use it in GitHub Desktop.
import cerberus
document = {
'a_list': [
{
'name': 'a1',
'value': 1,
},
{
'name': 'a2',
'value': 2,
},
{
'name': 'a3',
'value': 'wrong',
},
{
'name': 'a100',
'value': 'wrong',
}
]
}
schema = {
'a_list': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'name': {
'type': 'string',
},
'value': {
'type': 'integer',
}
}
}
}
}
v = cerberus.Validator(schema)
if not v.validate(document):
print('errors: {}'.format(v.errors))
else:
print('ok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment