Skip to content

jqnatividad/jsonschema-rs

This branch is 85 commits behind Stranger6667/jsonschema:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c1105d3 Β· Oct 26, 2024
Oct 5, 2024
Oct 26, 2024
Oct 26, 2024
Oct 26, 2024
Oct 26, 2024
Oct 8, 2024
Sep 28, 2024
Jun 9, 2020
Oct 26, 2024
Mar 3, 2024
Sep 15, 2024
Oct 25, 2024
Oct 26, 2024
May 1, 2024
Oct 26, 2024
Oct 26, 2024
Jan 28, 2021
Sep 13, 2024

Repository files navigation

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));

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

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

    // 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));

    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
  • 🌐 Remote reference fetching (network/file)
  • 🎨 Basic output style as per JSON Schema spec
  • πŸ”— Bindings for Python
  • πŸš€ 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 20-470x faster than valico and jsonschema_valid for complex schemas
  • Generally 3-20x faster than boon

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.

About

JSON Schema validation library

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 97.2%
  • Python 2.7%
  • Other 0.1%