MCPcopy Index your code
hub / github.com/Stranger6667/jsonschema

github.com/Stranger6667/jsonschema @python-v0.46.10

Chat with this repo
repository ↗ · DeepWiki ↗ · release python-v0.46.10 ↗ · + Follow
2,826 symbols 10,745 edges 195 files 218 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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: If both tls-aws-lc-rs and tls-ring features are enabled, aws-lc-rs takes precedence.

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.

Extension points exported contracts — how you extend this code

Validate (Interface)
The Validate trait represents a predicate over some JSON value. Some validators are very simple predicates such as "a va [103 …
crates/jsonschema/src/validator.rs
Retrieve (Interface)
Trait for retrieving resources from external sources. Implementors of this trait can be used to fetch resources that ar [14 …
crates/jsonschema-referencing/src/retriever.rs
RegexEngine (Interface)
(no doc) [4 implementers]
crates/jsonschema/src/regex.rs
AsyncRetrieve (Interface)
(no doc) [7 implementers]
crates/jsonschema-referencing/src/retriever.rs
PropertiesValidatorsMap (Interface)
A value that can look up property validators by name. [2 implementers]
crates/jsonschema/src/properties.rs
Sealed (Interface)
(no doc) [6 implementers]
crates/jsonschema-referencing/src/registry/input.rs
RegexError (Interface)
(no doc) [3 implementers]
crates/jsonschema/src/regex.rs
RetrieverBounds (Interface)
(no doc) [2 implementers]
crates/jsonschema-referencing/src/retriever.rs

Core symbols most depended-on inside this repo

new
called by 1052
crates/jsonschema/src/lib.rs
clone
called by 432
crates/jsonschema/src/paths.rs
push
called by 319
crates/jsonschema-referencing/src/path.rs
len
called by 224
crates/jsonschema/src/types.rs
join
called by 151
crates/jsonschema/src/paths.rs
iter
called by 139
crates/jsonschema/src/types.rs
from_str
called by 126
crates/jsonschema-referencing/src/uri.rs
options
called by 124
crates/jsonschema/src/lib.rs

Shape

Function 1,558
Method 853
Class 340
Enum 53
Interface 16
Route 6

Languages

Rust87%
Python12%
Ruby1%

Modules by API surface

crates/jsonschema/src/error.rs111 symbols
crates/jsonschema/src/lib.rs100 symbols
crates/jsonschema-referencing/src/registry/build.rs97 symbols
crates/jsonschema/src/keywords/format.rs92 symbols
crates/jsonschema/src/compiler.rs87 symbols
crates/jsonschema-rb/src/ser.rs86 symbols
crates/jsonschema/src/validator.rs75 symbols
crates/jsonschema/src/evaluation.rs74 symbols
crates/jsonschema-py/tests-py/test_jsonschema.py73 symbols
crates/jsonschema-py/src/lib.rs72 symbols
crates/jsonschema-cli/tests/cli.rs72 symbols
crates/jsonschema/src/options.rs64 symbols

For agents

$ claude mcp add jsonschema \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact