Boolean Parameter Parsing
This feature applies only to custom endpoints and does not apply to framework entities. To enable automatic boolean parsing for query and path parameters, you must use the z.stringbool Zod type in your schema. This does not support application/x-www-form-urlencoded or multipart/form-data.
Query and Path Parameters
When you receive data via query parameters (e.g., ?is_active=true) or path parameters (e.g., /user/true), express receives these as strings.
By using the z.stringbool Zod type, you can enable automatic case-insensitive type conversion. This allows your API to accept common human-readable strings as valid booleans.
Supported Mappings
The following table defines how various string inputs map to boolean types:
Truthy Values (becomes true) | Falsy Values (becomes false) |
|---|---|
true | false |
1 | 0 |
yes | no |
y | n |
on | off |
enabled | disabled |
Case Insensitivity
Mappings are case-insensitive. For example, YES, Yes, and yes will all be successfully parsed as true.
Request Bodies
Baseline does not automatically convert strings to booleans within request bodies. It requires explicit data types in the body to maintain strict type safety and prevent unexpected side effects.
Strict Typing in Request Bodies
Do not rely on string-to-boolean casting for application/json or multipart/form-data payloads. Passing a string where a boolean is expected in the schema will result in a validation error.
JSON Payloads
When using application/json, use native JSON boolean types (true or false without quotes).
// ✅ Valid: uses native boolean type
{
"is_active": true
}
// ❌ Invalid: results in a validation error
{
"is_active": "true"
}