DevTools Logo

AI JSON Type Inferencer

AI JSON Type Inferencer

Generate TypeScript interfaces and matching Zod schemas from raw JSON.

JSON input

Examples

Nested profile

Input
{"id":42,"profile":{"verified":true}}
Output
interface Root { id: number; profile: Profile }
const RootSchema = z.object({ ... })

Nested objects become separate named TypeScript and Zod representations.

Repeated status enum

Input
{"statuses":["ACTIVE","INACTIVE"]}
Output
statuses: ("ACTIVE" | "INACTIVE")[]
statuses: z.array(z.enum(["ACTIVE", "INACTIVE"]))

Repeated string values provide evidence for an enum constraint instead of widening every value to string.

About this tool

AI JSON Type Inferencer generates TypeScript interfaces and a matching Zod schema from valid JSON. The UI validates JSON.parse locally before enabling generation, accepts a root name (falling back to Root), and renders both raw code blocks with separate copy buttons.

The contract requires non-empty typescriptInterfaces and zodSchema plus optional notes, with no Markdown fences in either code field. The model must keep both representations structurally equivalent, create named interfaces and schemas for nested objects, preserve repeated-string enums, and infer optional properties only when evidence supports them.

Inference describes the supplied sample; it cannot prove every future payload shape. Review nullability, optionality, enum breadth, and runtime constraints before using the Zod schema as an API boundary.

How to use this tool

  1. Name the root

    Enter a valid root name or leave it blank to use Root.

  2. Paste JSON

    Provide syntactically valid JSON; malformed input keeps the generate action unavailable.

  3. Generate both forms

    Run the tool to receive TypeScript interfaces and a structurally matching Zod schema.

  4. Review and copy

    Compare nested types, nullability, and enums, then copy interfaces or schema into your project.

Use cases

API fixture modeling

Turn representative JSON responses into reviewable static types and runtime validation.

Event contract onboarding

Produce a first schema for nested event payloads before formalizing the producer contract.

Boundary validation

Use the generated Zod schema as a starting point for parsing untrusted request data.

Common mistakes

Mistake:Pasting JSON with comments or trailing commas.

Fix:Use strict JSON accepted by JSON.parse, then add comments outside the input.

Mistake:Assuming one sample reveals every enum value.

Fix:Use representative samples and manually confirm enum members before enforcing a narrow runtime schema.

Mistake:Using interfaces as runtime validation.

Fix:Parse at the boundary with the generated Zod schema; TypeScript interfaces disappear at runtime.

Frequently asked questions

What does the tool generate?

For valid JSON it generates raw TypeScript interfaces, a matching Zod schema, and optional notes. Both code fields must be non-empty and must not contain Markdown fences.

Why is the Generate action unavailable for malformed JSON?

The UI calls JSON.parse locally and marks input valid only when parsing succeeds. Comments, trailing commas, and other non-JSON syntax therefore need to be removed first.

How are nested objects, enums, and optional fields handled?

Nested objects receive separate named interfaces and matching schemas; repeated string values can remain enum constraints. Optional or nullable properties should be inferred only when the JSON evidence supports them.

Can the generated interface validate runtime data?

No. TypeScript interfaces disappear at runtime. Use the generated Zod schema to parse data at a boundary, then review its inferred constraints against real payloads.

References & standards