Skip to content

jsonValidation

const jsonValidation: (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.

JsonValidationConfig

Policy

import { jsonValidation } from "@homegrower-club/stoma";
// With Zod
jsonValidation({
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();