Created
July 21, 2015 09:38
-
-
Save lancechentw/f111106af136602db27a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
from jsonschema import Draft4Validator, RefResolver | |
import json | |
import os | |
import sys | |
if len(sys.argv) != 3: | |
print("Usage: %s <data file> <schema file>" % sys.argv[0]) | |
exit(1) | |
with open(sys.argv[1]) as f: | |
data = json.loads(f.read()) | |
with open(sys.argv[2]) as f: | |
schema = json.loads(f.read()) | |
schemas_basedir = os.path.dirname(os.path.realpath(sys.argv[2])) | |
resolver = RefResolver('file://%s/' % schemas_basedir, schema) | |
Draft4Validator(schema, resolver=resolver).validate(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment