jsonschema
A crate for performing fast JSON Schema validation. It is fast due to schema compilation into a validation tree, which reduces runtime costs for working with schema parameters.
Supports:
- JSON Schema drafts 4, 6, 7 (except some optional test cases);
- Loading remote documents via HTTP(S);
Usage Examples:
A schema can be compiled with two main flavours:
- using default configurations
# use ;
# use json;
#
- using custom configurations (such as define a Draft version)
# use ;
# use json;
#
Example (CLI tool to highlight print errors)
use ;
use json;
let schema = json!;
let instance = json!;
let compiled = options
.with_draft
.compile
.expect;
let result = compiled.validate;
if let Err = result
Each error has an instance_path
attribute that indicates the path to the erroneous part within the validated instance.
It could be transformed to JSON Pointer via .to_string()
or to Vec<String>
via .into_vec()
.