jsonschema 0.19.0

JSON schema validaton library
Documentation

jsonschema

A high-performance JSON Schema validator for Rust.

use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let schema = json!({"maxLength": 5});
    let instance = json!("foo");

    // One-off validation
    assert!(jsonschema::is_valid(&schema, &instance));

    // Build & reuse (faster)
    let validator = jsonschema::compile(&schema)
        .expect("Invalid schema");

    // Iterate over errors
    if let Err(errors) = validator.validate(&instance) {
        for error in errors {
            eprintln!("Error: {}", error);
            eprintln!("Location: {}", error.instance_path);
        }
    }

    // Boolean result
    assert!(validator.is_valid(&instance));

    Ok(())
}

You also can use it from the command line via the jsonschema-cli crate.

$ jsonschema-cli schema.json -i instance.json

See more usage examples in the documentation.

Highlights

  • 📚 Support for popular JSON Schema drafts
  • 🔧 Custom keywords and format validators
  • 🌐 Remote reference fetching (network/file)
  • 🎨 Basic output style as per JSON Schema spec
  • 🔗 Bindings for Python, Ruby, and JavaScript
  • 💻 Command Line Interface

Supported drafts

Compliance levels vary across drafts, with newer versions having some unimplemented keywords.

  • Draft 2020-12
  • Draft 2019-09
  • Draft 7
  • Draft 6
  • Draft 4

You can check the current status on the Bowtie Report.

Notable Users

Performance

`jsonschema`` outperforms other Rust JSON Schema validators in most scenarios:

  • Up to 20-470x faster than valico and jsonschema_valid for complex schemas
  • Generally 2-3x faster than boon

For detailed benchmarks, see our full performance comparison.

Minimum Supported Rust Version (MSRV)

This crate requires Rust 1.70 or later.

Support

If you have questions, need help, or want to suggest improvements, please use GitHub Discussions.

Sponsorship

If you find jsonschema useful, please consider sponsoring its development.

Contributing

We welcome contributions! Here's how you can help:

See CONTRIBUTING.md for more details.

License

Licensed under MIT License.