diff options
author | Julian Berman <Julian+git@GrayVines.com> | 2012-06-18 23:17:13 -0400 |
---|---|---|
committer | Julian Berman <Julian+git@GrayVines.com> | 2012-06-18 23:17:13 -0400 |
commit | 69faf9185c2607dadc68ca96b57578cba2adcc94 (patch) | |
tree | 0af9eab31fc6b2c79b3ef33d1ce6b249a2479720 | |
parent | 4837056c3868eac6c0970bb8dbe10355d51164d1 (diff) | |
download | jsonschema-69faf9185c2607dadc68ca96b57578cba2adcc94.tar.gz |
Added an example of ErrorTree to the README.
-rw-r--r-- | README.rst | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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 ----------------- |