How it works
Paste a JSON sample — an API response, a config file, a database row — and get TypeScript declarations you can paste straight into your codebase:
- Every object becomes an
interface(ortype), named after its property:owner→Owner. - Arrays of objects are merged into one type named in the singular:
tasks→Task[],categories→Category[]. - Properties missing from some array items become optional (
estimate?: number). - Mixed values become unions:
[1, "a", null]→(string | number | null)[]. - Identical shapes are reused, so
fromandtocoordinates share oneFromtype instead of two copies. - Keys that aren’t valid identifiers (like
first-name) are quoted automatically.
Example
{
"id": 42,
"owner": { "id": 7, "name": "Linh" },
"tasks": [
{ "id": 1, "done": true, "estimate": 3 },
{ "id": 2, "done": false, "assignee": "Minh" }
]
}
becomes
export interface Root {
id: number;
owner: Owner;
tasks: Task[];
}
export interface Owner {
id: number;
name: string;
}
export interface Task {
id: number;
done: boolean;
estimate?: number;
assignee?: string;
}
Options
- Root name — the name of the top-level type, e.g.
UserorApiResponse. - Declare as —
interfaceortypealias. - Export — add
exportso the types can be imported from other files.
Tips for better types
- Use real responses, not hand-written samples. Capture a few responses from your API and combine them into an array so optional fields are detected.
- Refine after generating. Narrow
stringto string-literal unions where you know the values (status: "open" | "closed"), and replacenullwith the real type. - Keep types next to the code that fetches the data, and regenerate them when the API changes.
- Need runtime checks too? Generate a matching schema with JSON to Zod instead of maintaining interfaces by hand.
Common mistakes
- Typing from one object. With a single sample, every property is required. Combine several responses into an array so fields that are sometimes missing become optional.
- Empty arrays and objects.
[]becomesunknown[]and{}becomesRecord<string, unknown>, because there is nothing to infer from. Replace them once you know the real shape. - Mixed arrays.
[1, "x"]becomes(string | number)[]. That is often a sign the API returns different shapes in different cases, so check it before narrowing the type.
If your sample isn’t valid JSON (copied from logs or an LLM), the error panel offers Fix with JSON Repair, or open JSON Repair directly. To browse a large payload before typing it, use the JSON Viewer. For backend code, the same sample produces Go structs or Pydantic models.
Frequently asked questions
How are optional properties detected?
When an array contains several objects, the generator merges them. A property that appears in some objects but not all is marked optional with `?`. Give it a representative sample — the more varied the objects, the more accurate the types.
Why is a field typed as `null`?
Because every sample value for that field was null, so there is no way to know the real type. Replace `null` with the expected type (for example `string | null`) or provide a sample where the field has a value.
Interface or type — which should I choose?
Both describe object shapes equally well. Interfaces can be extended and merged and give slightly clearer error messages; type aliases are required for unions and mapped types. Many teams simply pick one for consistency.
Does it validate data at runtime?
No. TypeScript types disappear at compile time. To validate API responses at runtime, pair these types with a schema library such as Zod, Valibot or ArkType.
Is my JSON uploaded?
No. Type generation runs entirely in your browser — nothing is uploaded.
Last updated