Registry / serialization / schemars

schemars

JSON →
library1.2.1rscratesunverified

Generate JSON Schemas from Rust code.

# Cargo.toml [dependencies] schemars = "1.2.1"
INSTALL
IMPORT
SIG · SCHEMARS
S
schemars
serializationrustv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JsonSchema
use schemars::JsonSchema;

Derive JsonSchema and generate a JSON Schema for a struct.

use schemars::JsonSchema; use serde::Serialize; #[derive(Serialize, JsonSchema)] struct MyStruct { name: String, age: u32, } fn main() { let schema = schemars::schema_for!(MyStruct); println!("{}", serde_json::to_string_pretty(&schema).unwrap()); }
Debug
Known issues
gotchaRequires serde derive for structs to work with schema_for!
fix
Add serde::Serialize or serde::Deserialize derive to your struct.
affects: >=1.0.0
Upgrade
Version history
1.2.1latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
10
Resources
schemars — cargo add schemars · libregistry