jsonValidation
constjsonValidation: (config?) =>Policy
Defined in: src/policies/transform/json-validation.ts:58
Pluggable JSON body validation policy.
Validates the request body using a user-provided function. When no
validate function is configured, checks that the body is parseable JSON.
Requests with content types not in the configured list pass through
without validation.
Parameters
Section titled “Parameters”config?
Section titled “config?”Returns
Section titled “Returns”Example
Section titled “Example”import { jsonValidation } from "@homegrower-club/stoma";
// With ZodjsonValidation({ validate: (body) => { const result = myZodSchema.safeParse(body); return { valid: result.success, errors: result.success ? undefined : result.error.issues.map(i => i.message), }; },});
// Just validate JSON is parseable (no validate function)jsonValidation();