MIT License

项目介绍

Stranger6667/jsonschema 是一个托管在 GitHub 上的开源项目,主要使用 Rust 编写,采用 MIT License 许可证,目前获得 833 个 Star、135 次 Fork。

仓库全名
Stranger6667/jsonschema
开源许可证
MIT License
Star 数
833
Fork 数
135
未关闭 Issue
8

README 摘要

jsonschema A high-performance JSON Schema validator for Rust. You also can use it from the command line via the jsonschema-cli crate. See more usage examples in the documentation. ⚠️ Upgrading from older versions? Check our Migration Guide for key changes. Playground If you'd like to try jsonschema, you can check the WebAssembly-powered playground to see the results instantly. Highlights 📚 Full support for popular…

完整内容见 GitHub 原始 README 或本页 。

常见问题

jsonschema 用什么语言开发?

主要使用 Rust 编写,采用 MIT License 许可证,目前有 833 个 Star。

jsonschema 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 jsonschema 的源码?

可以直接克隆仓库:git clone https://github.com/Stranger6667/jsonschema.git,默认分支为 master;安装与运行步骤见仓库 README。

jsonschema 最近还在维护吗?

仓库最近一次更新为 1 天前,当前有 8 个未关闭 Issue;Star 数为 833,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

A high-performance JSON Schema validator for Rust

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1111
价值分
540
活跃状态
活跃

语言占比

CSS
HTML
JavaScript
Just
Python
RenderScript
Ruby
Rust
Shell

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

    // Generated validators are significantly faster than runtime ones,
    // so prefer them when the schema is known at build time.
    // Requires the `macros` feature.
    // Inline schema, or `path = "schema.json"` to load from a file
    #[jsonschema::validator(schema = r#"{"maxLength": 5}"#)]
    struct Short;

    assert!(Short::is_valid(&instance));
    Short::validate(&instance)?;

    Ok(())
}

You also can use it from the command line via the jsonschema-cli crate.

$ jsonschema-cli validate schema.json -i instance.json

See more usage examples in the documentation.

⚠️ Upgrading from older versions? Check our Migration Guide for key changes.

Playground

If you’d like to try jsonschema, you can check the WebAssembly-powered playground to see the results instantly.

Highlights

  • 📚 Full support for popular JSON Schema drafts
  • 🔧 Custom keywords and format validators
  • ⚡ Compile-time validators for Rust, Python and Ruby extension modules
  • 🌐 Blocking & non-blocking remote reference fetching (network/file)
  • 📦 Schema bundling into Compound Schema Documents, and $ref dereferencing
  • 🎨 Structured Output v1 reports (flag/list/hierarchical)
  • ✨ Meta-schema validation for schema documents, including custom metaschemas
  • 🧮 Experimental schema canonicalization
  • 🧩 Validation of custom in-memory JSON representations
  • 🔗 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. The numbers below are for the runtime validator, which compiles a schema into a reusable Validator:

  • 88-1,851x faster than valico and 11-117x faster than jsonschema_valid for complex schemas (>1,000,000x on FHIR)
  • Generally 4.4-113x faster than boon, >340x on FHIR, and >9000x for recursive schemas

When the schema is known at build time, the #[jsonschema::validator] macro (macros feature) generates a specialized validator at compile time. This avoids schema compilation at runtime and validates roughly 1.7-6.5x faster than the runtime validator across our benchmark schemas.

For detailed benchmarks, see our full performance comparison.

Cargo features

Feature Default Enables
resolve-http ✅ Fetching remote references over HTTP
resolve-file ✅ Reading references from the filesystem
tls-aws-lc-rs ✅ TLS provider for resolve-http
idna ✅ The idn-hostname and idn-email formats
tls-ring ring as the TLS provider instead of aws-lc-rs
resolve-async Non-blocking reference resolution
arbitrary-precision Arbitrarily large integers and exact decimal values
macros The #[jsonschema::validator] compile-time validator
pyo3 Validating Python objects in place, and backend = Pyo3 for the macro
magnus Validating Ruby objects in place, and backend = Magnus for the macro
jsonb Validating Postgres jsonb values in place

Turning off idna drops the IDNA and ICU dependencies; idn-hostname and idn-email are then treated as unknown formats.

Minimum Supported Rust Version (MSRV)

This crate requires Rust 1.85.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.60",
    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.

评论

暂无评论