Schema validation library is available globally in every backend script. It provides a Joi-like fluent API to validate, coerce, and sanitize incoming data — especially request.body from POST requests, but usable with any object.
The library is pure JavaScript and runs directly in the sandbox. No imports needed — Schema is a global.
Quick start
How it works
- Define a schema using
Schema.string(),Schema.number(), etc. - Chain validators:
.required(),.min(5),.email(), etc. - Call
schema.validate(data)— returns{ valid, value, errors } - If
validistrue,valuecontains a deep-cloned, type-coerced copy of the input - If
validisfalse,errorsis an array of human-readable error messages
validate() returns a deep clone of the input. The original request.body is never mutated. Unknown keys in objects are silently dropped — only keys defined in the schema are kept.Types
Schema.string()
Validates that the value is a string.
Schema.number()
Validates that the value is a number. Strings like "42" are auto-coerced.
Schema.boolean()
Validates that the value is a boolean. Strings "true", "1", "false", "0" are auto-coerced.
Schema.array()
Validates arrays. Use .items() to validate each element.
Schema.object()
Validates objects. Pass a key map to define the shape.
result.value. This prevents users from injecting unexpected fields.
Dynamic keys
For objects where keys are not known ahead of time, use.pattern_values():
Schema.any()
Accepts any type. Useful with .required() or .valid().
Modifiers
Type coercion
The validator automatically coerces compatible types:
Non-coercible values fail validation (e.g.
"hello" for Schema.number()).
Custom validators
Use.custom() for logic that built-in methods don’t cover:
(value, label) and should return an error string if validation fails, or nothing/undefined if it passes.
Full POST example
A page at/api/submit-checkin that validates and stores data: