This tool reads a JSON value and writes TypeScript interface declarations for it. Keys are kept exactly as they are; arrays of objects are merged into one interface, keys present in only some items get ?, and mixed values become union types.
Use it to type fetch or axios responses on the frontend, to declare return types for Next.js API routes or Express handlers, or whenever a backend only documents example responses and no type definitions.
Type name (e.g. ChannelHistory); it is kept in the URL as ?name=.types.ts and use it via import type { ChannelHistory } from "./types".{
"channel": "general",
"messages": [
{ "id": "m1", "user": "kim", "text": "deploy done", "reactions": ["+1"] },
{ "id": "m2", "user": "lee", "text": null, "edited": true, "attachment": { "type": "image", "url": "https://cdn.example.com/a.png" } }
],
"cursor": 42
}export interface ChannelHistory {
channel: string;
messages: Message[];
cursor: number;
}
export interface Message {
id: string;
user: string;
text: string | null;
reactions?: string[];
edited?: boolean;
attachment?: Attachment;
}
export interface Attachment {
type: string;
url: string;
}
Both messages are merged into a single Message interface; reactions, edited and attachment appear in only one of them, so they get ?. text mixes a string and null, giving string | null. Element interfaces take the singular form of the key (messages → Message).
export interface, ready to import elsewhere."a-b", "2fa") are quoted.?:).string | number); null is appended last as | null. Mixed arrays become (string | number)[].unknown[].export type Root = RootItem[];.Pass the type as a generic, e.g. const res = await axios.get<ChannelHistory>(url), and the editor warns you that res.data.messages[0].text may be null.
For internal or external APIs with no SDK or @types package, one sample response is enough to produce a type definition file to share with the team.
Generate interfaces from Storybook or test mock JSON and use them as component props types; when the mocks drift from the components, the compiler tells you.
number (no integer/float split), and date strings are string."status": "active", come out as string; narrow them to literal unions ("active" | "banned") yourself.Profile2.type aliases instead of interfaces?A type alias is used only for a top-level array or primitive; objects are always interfaces. Rewriting export interface X { ... } as export type X = { ... }; behaves the same for this purpose.
?) and | null kept separate?They mean different things: ? says the key may be absent (undefined), while | null says the key is there with a null value. With strictNullChecks on, you handle the two cases differently.
A TypeScript type describes the actual object, so renamed keys would no longer match the response. If you want camelCase in your code, define a separate type for the result of your mapping function.
This page emits plain type declarations only. The TypeORM, Sequelize and Mongoose tabs at the top generate entity and model code from the same JSON.