How to generate typescript interfaces via json schema
- Step 1Paste the API response JSON — Use a real API response sample — the more complete the sample, the more accurate the type inference. For arrays, paste a sample that includes at least 2-3 elements to infer the item schema correctly.
- Step 2Generate the JSON Schema — Click Generate. The output draft-07 schema captures all object shapes, array item types, and primitive types from the sample.
- Step 3Refine nullable and optional fields — Fields that are null in the sample get type: null. Change these to type: [string, null] (nullable) or remove them from required to model optional nullable fields accurately.
- Step 4Feed into json-schema-to-typescript — Install the package: npm install json-schema-to-typescript. Then: npx json2ts schema.json > types.ts. The output TypeScript interfaces are ready for import in your API client or Next.js server component.
Frequently asked questions
How does this differ from using the JSON to TypeScript tool directly?+
The JSON to TypeScript tool generates interfaces directly from a sample JSON value. Generating via JSON Schema first gives you an intermediate schema that you can version-control, share with back-end teams, and use for validation as well as type generation. The schema is the authoritative contract; the TypeScript types are derived from it.
Can I generate types for discriminated unions (e.g. different event types)?+
The generator infers the structure of each sample. For discriminated unions, generate a schema from each event type variant separately, then manually combine them using anyOf in the schema. json-schema-to-typescript maps anyOf to TypeScript union types.
Is the JSON sample transmitted to JAD Apps?+
No. Schema inference runs entirely in your browser. API samples, response data, and field names are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.