Nested JSON to TypeScript
Nested objects are hoisted into their own named interfaces rather than inlined, so the output stays readable.
Input
{
"id": 1,
"author": {
"name": "Ada",
"profile": {
"bio": "Mathematician",
"url": "https://example.com"
}
}
}An object with 2 nested shapes.
3 interfaces · 6 fields · 3 levels deep
Where this sample is ambiguous
Note
Whole numbers are still `number`
Every numeric value in the sample was a whole number, but JSON has a single number type and cannot express the difference. The output uses `number`.
Fix: If a field is genuinely an integer, tighten it by hand: `z.number().int()`.
TypeScript
export interface Root {
id: number;
author: Author;
}
export interface Author {
name: string;
profile: Profile;
}
export interface Profile {
bio: string;
url: string;
}Zod
import { z } from 'zod';
export const ProfileSchema = z.object({
bio: z.string(),
url: z.string(),
});
export const AuthorSchema = z.object({
name: z.string(),
profile: ProfileSchema,
});
export const RootSchema = z.object({
id: z.number(),
author: AuthorSchema,
});Convert your own JSON
Paste a sample on the home page, or call the API or MCP server. This page is also available as markdown.