[][src]Crate jsonschema

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 6, 7 (all test cases);
  • Loading remote documents via HTTP(S);

Example:

use jsonschema::{JSONSchema, Draft, CompilationError};
use serde_json::json;

fn main() -> Result<(), CompilationError> {
   let schema = json!({"maxLength": 5});
   let instance = json!("foo");
   let compiled = JSONSchema::compile(&schema, Some(Draft::Draft7))?;
   let result = compiled.validate(&instance);
   if let Err(errors) = result {
       for error in errors {
           println!("Validation error: {}", error)
       }   
   }
   Ok(())
}

Structs

JSONSchema
ValidationError

An error that can occur during validation.

Enums

CompilationError
Draft

Functions

is_valid

Validates instance against schema. Draft version is detected automatically.

Type Definitions

ErrorIterator