Use this JSON to TypeScript generator to create type-safe interfaces and types from JSON samples for frontend apps and Node.js services.
Step 1 – Paste a JSON sample
- Paste a representative JSON object or array into the left editor.
- Include nested objects, arrays, and nullable fields so types are inferred correctly.
- Use
Import to load JSON from a file, URL, or sample data.
Step 2 – Choose TypeScript generation options
- Set a
Root Type Name that matches your model (for example Root). - Pick a null handling strategy (
Optional (?) vs Union (| null)) to match your codebase. - Decide whether you want
interfaces or type aliases for the output.
Step 3 – Review the generated code
- Check field names, types, and how arrays/objects are modeled.
- Adjust options like
Root Type Name, null handling, and frameworks if available. - If a field is inferred incorrectly, tweak your sample JSON and regenerate.
Step 4 – Use the generated types
- Paste the output into your project and export it from your types module.
- Use the types for API responses, DTOs, and runtime parsing boundaries.
- Regenerate when your JSON payload changes to keep clients in sync.
Step 5 – Copy or download
- Copy the output into your project or download it as a file.
- Run your formatter/linter to match your code style.
- Add JSON parsing/serialization libraries if your language requires them.
Example output (simplified)
// JSON input
{
"id": 123,
"name": "Maeve Winters",
"email": "maeve@example.com",
"active": true,
"roles": ["admin", "editor"],
"metadata": { "plan": "pro" },
"createdAt": "2024-03-01T10:15:00Z",
"score": 99.5,
"notes": null
}
// Generated TypeScript types (simplified)
export interface Metadata {
plan: string;
}
export interface Root {
id: number;
name: string;
email: string | null;
active: boolean;
roles: string[];
metadata: Metadata;
createdAt: string;
score: number;
notes: null;
}