Public
Script
March 30, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
import { z } from "npm:zod";
const zodStringToJSON = () =>
z.string().transform((str, ctx): z.infer<z.ZodType<unknown>> => {
try {
return JSON.parse(str);
} catch (e) {
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
return z.NEVER;
}
});
export { zodStringToJSON };
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 30, 2024