Objects
Validating complex nested structures.
Objects
Objects define the shape of your data. Rod supports strict mode, stripping unknown keys, and deep nesting.
let schema = rod_obj! {
name: string(),
age: number().int()
};const schema = rod.object({
name: rod.string(),
age: rod.number().int()
});schema = rod.object({
"name": rod.string(),
"age": rod.number().int()
})Unknown Keys
.strip(): (Default) Silently removes keys not defined in the schema..strict(): Fails validation if any unknown keys are present..passthrough(): Retains unknown keys in the output.
rod_obj! { ... }.strict()rod.object({ ... }).strict()rod.object({ ... }).strict()JS Parsing Modes
In TypeScript, you can specify how Rod reads your JS objects:
mode: 'lazy'(Default): Reads fields only when needed. Best for large objects.mode: 'eager': Serializes the whole object to Rust first. Best for massive arrays of simple objects.