Created
July 22, 2018 00:13
-
-
Save ricardochaves/47155e3ca20e828303e299638954a559 to your computer and use it in GitHub Desktop.
Schema Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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