summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian+git@GrayVines.com>2012-06-18 23:17:13 -0400
committerJulian Berman <Julian+git@GrayVines.com>2012-06-18 23:17:13 -0400
commit69faf9185c2607dadc68ca96b57578cba2adcc94 (patch)
tree0af9eab31fc6b2c79b3ef33d1ce6b249a2479720
parent4837056c3868eac6c0970bb8dbe10355d51164d1 (diff)
downloadjsonschema-69faf9185c2607dadc68ca96b57578cba2adcc94.tar.gz
Added an example of ErrorTree to the README.
-rw-r--r--README.rst27
1 files changed, 27 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index a6fa856..26e6a2e 100644
--- a/README.rst
+++ b/README.rst
@@ -53,6 +53,33 @@ Features
* Small and extensible
+* Programmatic querying of which properties or items failed validation.
+
+ >>> from jsonschema import ErrorTree, Validator
+ >>> schema = {
+ ... "type" : "array",
+ ... "items" : {"type" : "number", "enum" : [1, 2, 3]},
+ ... "minItems" : 3,
+ ... }
+ >>> instance = ["spam", 2]
+ >>> v = Validator()
+ >>> tree = ErrorTree(v.iter_errors(instance, schema))
+
+ >>> sorted(tree.errors)
+ ['minItems']
+
+ >>> 0 in tree
+ True
+
+ >>> 1 in tree
+ False
+
+ >>> sorted(tree[0].errors)
+ ['enum', 'type']
+
+ >>> print(tree[0].errors["type"].message)
+ 'spam' is not of type 'number'
+
Schema Versioning
-----------------