Expand description
JSON Schema type construction with validation, code generation, and binary layout.
Inspired by TypeBox (TypeScript).
§Example
use typebox::{SchemaBuilder, Value, check, create};
// Define a schema
let person = SchemaBuilder::object()
.field("id", SchemaBuilder::int64())
.field("name", SchemaBuilder::string().build())
.optional_field("email", SchemaBuilder::string().build())
.named("Person");
// Create a default value
let value = create(&person).unwrap();
assert!(check(&person, &value));
// Build values manually
let alice = Value::object()
.field("id", Value::Int64(1))
.field("name", Value::String("Alice".to_string()))
.build();
assert!(check(&person, &alice));§Feature Flags
codegen- Generate Rust/TypeScript code from schemasfake- Generate random test data (requiresfakeandrandcrates)safetensor- SafeTensor file supportffi- C-compatible FFI types
Re-exports§
pub use builder::SchemaBuilder;pub use error::CastError;pub use error::CleanError;pub use error::CreateError;pub use error::Error;pub use error::PatchError;pub use format::FormatRegistry;pub use format::FormatValidator;pub use layout::Layout;pub use registry::SchemaRegistry;pub use schema::LiteralValue;pub use schema::Schema;pub use schema::SchemaKind;pub use schema::StringFormat;pub use validate::validate;pub use validate::validate_with_format;pub use validate::validate_with_registry;pub use value::Value;pub use value::cast;pub use value::cast;pub use value::check;pub use value::check;pub use value::check_with_errors;pub use value::clean;pub use value::clean;pub use value::clone;pub use value::clone;pub use value::create;pub use value::create;pub use value::delta;pub use value::delta;pub use value::diff_summary;pub use value::equal;pub use value::equal;pub use value::patch;pub use value::patch;pub use value::Delta;pub use value::Edit;
Modules§
- builder
- Schema builder API for constructing JSON Schema types.
- error
- Error types for schema validation and value operations.
- format
- Format registry for custom string format validation.
- layout
- Binary layout calculation for schemas.
- registry
- Schema registry for
$refresolution and named schema lookup. - schema
- Schema types for JSON Schema construction.
- validate
- Schema validation for values.
- value
- Value type and operations.
Constants§
- VERSION
- Crate version string.