JSON schema validator for python
Note
Only a subset of schema features are currently supported. Unsupported features are detected and raise a NotImplementedError when you call Validator.validate()
Warning
This implementation was based on the second draft of the specification A third draft was published on the 22nd Nov 2010. This draft introduced several important changes that are not yet implemented.
See also
http://json-schema.org/ for details about the schema
JSON schema object
Enumeration of possible correct values.
Must be either None or a non-empty list of valid objects. The list must not contain duplicate elements.
Note
JSON schema specifications says that this value SHOULD follow the EMCA 262/Perl 5 format. We cannot support this so we support python regular expressions instead. This is still valid but should be noted for clarity.
:returns None or compiled regular expression
The properties property contains schema for each property in a dictionary.
The dictionary name is the property name. The dictionary value is the schema object itself.
Return the ‘type’ property of this schema.
The return value is always a list of correct JSON types. Correct JSON types are one of the pre-defined simple types or another schema object.
List of built-in simple types: * ‘string’ * ‘number’ * ‘integer’ * ‘boolean’ * ‘object’ * ‘array’ * ‘any’ (default)
A bug in the schema prevents the program from working
A bug in the validated object prevents the program from working.
The error instance has several interesting properties:
message: Old and verbose message that contains less helpful message and lots of JSON data (deprecated). new_message: short and concise message about the problem object_expr: A JavaScript expression that evaluates to the object that failed to validate. The expression always starts with a root object called 'object'. schema_expr: A JavaScript expression that evaluates to the schema that was checked at the time validation failed. The expression always starts with a root object called 'schema'.
JSON Schema validator.
Can be used to validate any JSON document against a Schema.
Validate specified JSON object obj with specified Schema instance schema.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | True on success |
Raises: |
|
Validate specified JSON text (data_text) with specified schema (schema text). Both are converted to JSON objects with simplesjon.loads().