Skip to content

Stranger6667/jsonschema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1,202 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

jsonschema

crates.io docs.rs build status codecov.io Supported Dialects

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));
    assert!(jsonschema::validate(&schema, &instance).is_ok());

    // Build & reuse (faster)
    let validator = jsonschema::validator_for(&schema)?;

    // Fail on first error
    assert!(validator.validate(&instance).is_ok());

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

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

    // Structured output (JSON Schema Output v1)
    let evaluation = validator.evaluate(&instance);
    for annotation in evaluation.iter_annotations() {
        eprintln!(
            "Annotation at {}: {:?}",
            annotation.schema_location,
            annotation.annotations.value()
        );
    }

    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 older versions? Check our Migration Guide for key changes.

Highlights

  • πŸ“š Full support for popular JSON Schema drafts
  • πŸ”§ Custom keywords and format validators
  • 🌐 Blocking & non-blocking remote reference fetching (network/file)
  • 🎨 Structured Output v1 reports (flag/list/hierarchical)
  • ✨ Meta-schema validation for schema documents, including custom metaschemas
  • πŸ”— Bindings for Python and Ruby
  • πŸš€ WebAssembly support
  • πŸ’» Command Line Interface

Supported drafts

The following drafts are supported:

  • 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 75-645x faster than valico and jsonschema_valid for complex schemas
  • Generally 2-52x faster than boon, and >5000x faster for recursive schemas

For detailed benchmarks, see our full performance comparison.

Minimum Supported Rust Version (MSRV)

This crate requires Rust 1.83.0 or later.

TLS Configuration

By default, jsonschema uses aws-lc-rs as the TLS cryptography provider, which is the default one in reqwest.

Using Ring Instead

You can opt into using ring as the TLS provider:

[dependencies]
jsonschema = { version = "0.42", default-features = false, features = ["resolve-http", "resolve-file", "tls-ring"] }

Note: To ensure aws-lc-rs is not pulled in, disable default features (which include tls-aws-lc-rs) and explicitly enable tls-ring with the features you need.

Priority behavior: If both tls-aws-lc-rs and tls-ring features are enabled (e.g., through dependency resolution or --all-features), aws-lc-rs takes precedence. To use ring, you must disable default features as shown above.

When to use tls-ring:

  • You encounter errors like undefined symbol: aws_lc_0_xx_x_EVP_PKEY_bits when building from source
  • You're on a Linux distribution where aws-lc-rs is not available or compatible
  • You have specific requirements to use ring

Warning: Using tls-ring may cause conflicts if your application also depends on other libraries that use the default aws-lc-rs provider. For most users, the default configuration is recommended.

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.

About

A high-performance JSON Schema validator for Rust

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Contributors 52