diff --git a/README.md b/README.md index b26b12e..0c39828 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,47 @@ Testing You will need tox (get it from pip) as python2.7 $ tox + +Quickstart +========== + +The fastest way to validate a schema against json is to use the `validate()` function provided in `json_schema_validator.shortcuts`. + +To import 'shortcuts' use: +`from json_schema_validator.shortcuts import *` + +The function `validate()` provided by 'shortcuts' takes two positional arguments, `schema text` and `json text`. Simply pass in a valid json schema as raw string and then the json text to validate as a raw string: + + from json_schema_validator.shortcuts import * + + schema = open("a_schema.json", 'r') + json = open("some_json.json", 'r') + + validate(schema.read(), json.read()) + +`validate()` will first test the schema parameter against it's schema specification, followed by the json parameter against the schema parameter. Problems with: + - json syntax in either schema or json subject documents + - adherence to schema specifications + - adherence of your subject json to your provided schema + + + Will throw exceptions, otherwise this function will return `True` + +Checking a Schema against a Schema specification +================================================ + +Given the scenario that you have just created a new schema and you want to test that it is valid json/ that it adheres to your provided schema specification draft, you should 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](https://docs.python.org/3.8/library/json.html) 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)