Skip to content

Instantly share code, notes, and snippets.

@ChristianHernon
ChristianHernon / safeParseJson.md
Created August 18, 2026 00:35
Type Safe Parse JSON

Zod version:

import { z } from "zod";

type JsonParseResult<T> = { ok: true; value: T } | { ok: false; error: Error };

const parseJson = <T>(
  input: string,
  schema: z.ZodType<T>,