Skip to content
DEVPANTRY.COM

JSON to TypeScript & Zod

Turn a JSON example into TypeScript types and a Zod schema. Compare both outputs and copy the code you need—your JSON is processed on your device.

export interface Root {
  users: Array<{
    id: number;
    name?: string;
    active: boolean;
  }>;
  nextPage: null;
}

Create TypeScript types from real JSON examples

  1. Paste a JSON object, array, or primitive value into the input.
  2. Review the inferred TypeScript interface or type alias. Check optional properties and unions against your API contract.
  3. Copy the output into your project. Switch format to compare compile-time types and runtime validation.

Interfaces, arrays, and primitive roots

Object samples generate an interface. An array, string, number, boolean, or null at the root generates a type alias. Use the Zod tab when the response also needs validation at runtime.

// JSON input: [1, "pending", null]
export type Root = Array<number | string | null>;

How arrays and optional fields are inferred

Every array element is inspected. For [{"id":1},{"id":2,"name":"Ada"}], name is optional. Mixed value types become unions. An empty array uses an unknown element type until an example supplies more information.

Continue the workflow

Use API response fixtures as examples, then exercise your schema with the mock data generator. Read the JSON-to-Zod validation guide for a complete example.