Use case
As proposed by @dreamorosi in #2892 it'd be great to extract the helper function from the docs to a dedicated export, so users can utilize it from the IDE instead of consulting the docs.
Solution/User Experience
import { z, type ZodSchema } from 'zod';
const JSONStringified = (schema: ZodSchema) =>
z
.string()
.transform((str, ctx) => {
try {
return JSON.parse(str);
} catch (err) {
ctx.addIssue({
code: 'custom',
message: 'Invalid JSON',
});
}
})
.pipe(schema);
export { JSONStringified };
Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Use case
As proposed by @dreamorosi in #2892 it'd be great to extract the helper function from the docs to a dedicated export, so users can utilize it from the IDE instead of consulting the docs.
Solution/User Experience
Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.