Home

Awesome

jsonschema

<img alt="crates.io" src="https://img.shields.io/crates/v/jsonschema.svg?style=flat-square&color=fc8d62&logo=rust" height="20"> <img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-jsonschema-66c2a5?style=flat-square&labelColor=555555&logo=docs.rs" height="20"> <img alt="build status" src="https://img.shields.io/github/actions/workflow/status/Stranger6667/jsonschema-rs/ci.yml?branch=master&style=flat-square" height="20"> <img alt="codecov.io" src="https://img.shields.io/codecov/c/gh/Stranger6667/jsonschema-rs?logo=codecov&style=flat-square&token=B1EnafGlRL" height="20"> <img alt="Supported Dialects" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Frust-jsonschema%2Fsupported_versions.json&style=flat-square">

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::validator_for(&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.

⚠️ Upgrading from pre-0.20.0? Check our Migration Guide for key changes.

Highlights

Supported drafts

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

You can check the current status on the Bowtie Report.

Notable Users

Performance

jsonschema outperforms other Rust JSON Schema validators in most scenarios:

For detailed benchmarks, see our full performance comparison.

Minimum Supported Rust Version (MSRV)

This crate requires Rust 1.70 or later.

Acknowledgements

This library draws API design inspiration from the Python jsonschema package. We're grateful to the Python jsonschema maintainers and contributors for their pioneering work in JSON Schema validation.

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.