jsonforge 0.1.0

A Rust procedural macro for generating JSON schema validators from Rust types
Documentation
/// A Rust type inferred from a JSON value.
#[derive(Debug, Clone, PartialEq)]
pub enum SchemaType {
    Bool,
    Integer,
    Float,
    Str,
    Optional(Box<SchemaType>),
    Array(Box<SchemaType>),
    /// A nested struct (for nested JSON objects).
    Struct(StructSchema),
}

/// Schema for a JSON object modelled as a Rust struct.
#[derive(Debug, Clone, PartialEq)]
pub struct StructSchema {
    pub fields: Vec<FieldSchema>,
}

#[derive(Debug, Clone, PartialEq)]
pub struct FieldSchema {
    /// The original JSON key.
    pub json_key: String,
    /// The sanitised Rust identifier name.
    pub rust_name: String,
    pub ty: SchemaType,
}

/// The shape of the top-level JSON value.
#[derive(Debug, Clone)]
pub enum TopLevel {
    /// `{ "key": <uniform struct value>, … }` → a string-keyed PHF/sorted map.
    Map { entry: StructSchema },
    /// `[ <uniform value>, … ]` → a fixed-length static array.
    Array { entry: SchemaType },
    /// Any other JSON object → a single struct.
    Struct(StructSchema),
}