Skip to content

Instantly share code, notes, and snippets.

@lancechentw
Created July 21, 2015 09:38
Show Gist options
  • Save lancechentw/f111106af136602db27a to your computer and use it in GitHub Desktop.
Save lancechentw/f111106af136602db27a to your computer and use it in GitHub Desktop.
#!/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