How do I validate a JSON Schema schema, in Python?

GDorn picture GDorn · Dec 11, 2012 · Viewed 15.3k times · Source

I am programmatically generating a JSON-Schema schema. I wish to ensure that the schema is valid. Is there a schema I can validate my schema against?

Please note my use of schema twice in that sentence and the title. I don't want to validate data against my schema, I want to validate my schema.

Answer

GDorn picture GDorn · Dec 11, 2012

Using jsonschema, you can validate a schema against the meta-schema. The core meta-schema is here, but jsonschema bundles it so downloading it is unnecessary.

from jsonschema import Draft3Validator
my_schema = json.loads(my_text_file) #or however else you end up with a dict of the schema
Draft3Validator.check_schema(my_schema)