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.jsonSee more usage examples in the documentation.
β οΈ Upgrading from older versions? Check our Migration Guide for key changes.
- π 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
The following drafts are supported:
You can check the current status on the Bowtie Report.
- Tauri: Config validation
- Apollo Router: Config file validation
- qsv: CSV record validation with custom keyword & format validator
jsonschema outperforms other Rust JSON Schema validators in most scenarios:
- Up to 75-645x faster than
valicoandjsonschema_validfor complex schemas - Generally 2-52x faster than
boon, and >5000x faster for recursive schemas
For detailed benchmarks, see our full performance comparison.
This crate requires Rust 1.83.0 or later.
By default, jsonschema uses aws-lc-rs as the TLS cryptography provider, which is the default one in reqwest.
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_bitswhen building from source - You're on a Linux distribution where
aws-lc-rsis 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.
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.
If you have questions, need help, or want to suggest improvements, please use GitHub Discussions.
If you find jsonschema useful, please consider sponsoring its development.
We welcome contributions! Here's how you can help:
- Share your use cases
- Implement missing keywords
- Fix failing test cases from the JSON Schema test suite
See CONTRIBUTING.md for more details.
Licensed under MIT License.