From f9b1e3225fc6b4f4942a59fa5dabad1b585acb25 Mon Sep 17 00:00:00 2001 From: Joseph Heck Date: Sun, 9 Mar 2014 17:04:29 -0700 Subject: [PATCH 1/2] adding in examples and links * Adding in an example of using the schema validator * Adding in a link to 'Understanding JSON Schema' at http://spacetelescope.github.io/understanding-json-schema/ --- docs/validate.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/validate.rst b/docs/validate.rst index 50b7456..342c2ac 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -14,6 +14,9 @@ The simplest way to validate an instance under a given schema is to use the .. autofunction:: validate +To learn more about creating json schema to validate your data, see +`Understanding JSON Schema `_ + The Validator Interface ----------------------- @@ -181,6 +184,16 @@ implements. .. autoclass:: Draft4Validator +For example, if you wanted to validate a schema you created against the Draft 3 +json schema, you could use:: + +.. code-block:: python + + + from jsonschema import Draft3Validator + my_schema = json.loads(my_schema_file) + Draft3Validator.check_schema(schema) + Validating Formats ------------------ @@ -260,3 +273,4 @@ color requires webcolors_ .. _rfc3987: http://pypi.python.org/pypi/rfc3987/ .. _strict-rfc3339: http://pypi.python.org/pypi/strict-rfc3339/ .. _webcolors: http://pypi.python.org/pypi/webcolors/ +.. _understanding_json_schema: http://spacetelescope.github.io/understanding-json-schema/ From ac0dee4bda82743aa0287a26e2a34f914b6d5ae4 Mon Sep 17 00:00:00 2001 From: Joseph Heck Date: Sun, 9 Mar 2014 20:45:02 -0700 Subject: [PATCH 2/2] updating per feedback updating per feedback --- docs/validate.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/validate.rst b/docs/validate.rst index 342c2ac..b63bd98 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -185,14 +185,24 @@ implements. .. autoclass:: Draft4Validator For example, if you wanted to validate a schema you created against the Draft 3 -json schema, you could use:: +json schema, you could use: .. code-block:: python - from jsonschema import Draft3Validator - my_schema = json.loads(my_schema_file) - Draft3Validator.check_schema(schema) + from jsonschema import Draft4Validator + + schema = { + "$schema": "http://json-schema.org/schema#" + + "type": "object", + "properties": { + "name": {"type": "string"}, + "email": {"type": "string"}, + } + "required": ["email"], + } + Draft4Validator.check_schema(schema) Validating Formats @@ -273,4 +283,3 @@ color requires webcolors_ .. _rfc3987: http://pypi.python.org/pypi/rfc3987/ .. _strict-rfc3339: http://pypi.python.org/pypi/strict-rfc3339/ .. _webcolors: http://pypi.python.org/pypi/webcolors/ -.. _understanding_json_schema: http://spacetelescope.github.io/understanding-json-schema/