Skip to content

Instantly share code, notes, and snippets.

@blokhin
Created January 14, 2017 15:41
Show Gist options
  • Save blokhin/f0770a154db6cc38ff2fb594aaa1738e to your computer and use it in GitHub Desktop.
Save blokhin/f0770a154db6cc38ff2fb594aaa1738e to your computer and use it in GitHub Desktop.
import sys
import ujson as json
from jsonschema import validate, Draft3Validator
try: f, t = sys.argv[1], sys.argv[2]
except IndexError: sys.exit("Usage: schema input_JSON")
schema = json.loads(open(f).read())
Draft3Validator.check_schema(schema)
target = json.loads(open(t).read())
if not target.get("npages") or not target.get("out") or target.get("error"):
sys.exit("Not a valid API response")
for entry in target["out"]:
validate(entry, schema)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment