34

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.

2 Answers 2

33

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)
Sign up to request clarification or add additional context in comments.

Comments

0

Since Draft 4, your schema should indicate what version of the draft it is evaluating against, so Python's jsonschema can get the proper evaluator from your schema itself:

from jsonschema.validators import validator_for
my_schema = json.loads(my_text_file)
ValidatorClass = validator_for(my_schema)
ValidatorClass.check_schema(my_schema)

Note however that this will protect you against omissions or incorrect types, but not typos or features not available in your metaschema version, since additional properties are allowed in json schemas themselves.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.