Closed
Description
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.
- add helper function
- add exports
- add tests all applicable built-in schemas that can have JSON stringified payload
- change parser docs how to use the helper function
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
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped