-
Notifications
You must be signed in to change notification settings - Fork 18
Checking a Schema against a Schema specification
SA edited this page Jan 10, 2020
·
1 revision
If you have just created a new schema and you want to test that it is valid json and that it adheres to your provided schema specification draft.
Firstly, use the 'Schema' class from json_schema_validator.schema. Instead of providing a raw string the Schema() constructor, Schema() requires a Python object (a dict).
To get your raw json string into this format use the json library's .load() method (or .loads() for a raw string json schema).
This means any syntax mistakes in your schema's json will throw exceptions when using json.load()/.loads() instead of inside of json_schema_validator functionality. See the example:
from json_schema_validator.schema import Schema
import json
schema = open("a_schema.json", 'r')
#convert to native python object via json library
schema_obj = json.load(schema)
validated = Schema(schema_obj)