Skip to content

Instantly share code, notes, and snippets.

@ricardochaves
Created July 22, 2018 00:13
Show Gist options
  • Save ricardochaves/47155e3ca20e828303e299638954a559 to your computer and use it in GitHub Desktop.
Save ricardochaves/47155e3ca20e828303e299638954a559 to your computer and use it in GitHub Desktop.
Schema Validation
from jsonschema import validate
from jsonschema import FormatChecker
data = {
"name": "Ricardo",
"image": "https://www.ricardobaltazar.com/static/principal/images/profilepic-new.jpg",
"age": 37,
"birth_date": "1981-06-21T12:42:31+00:32"
}
schema = {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"image": {
"type": "string",
"format": "uri"
},
"age": {
"type": "integer",
"minimum": 18,
"maximum": 150
},
"birth_date": {
"type": "string",
"format": "date-time"
}
},
"required": ["name"]
}
validate(data, schema, format_checker=FormatChecker())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment