How to generate TypeScript from JSON and review the result
Paste a representative JSON response into the KitLumi JSON to TypeScript Generator, choose Interfaces or Type aliases, and select Convert. The output is a starting point for static types. A single JSON sample cannot establish every value an API might return, and the declarations do not validate runtime responses.
How do you do it?
- Copy a representative JSON object or array. Remove credentials and personal information you do not need in your example.
- Choose Interfaces or Type aliases in the generator, then select Convert.
- Review the generated Root and nested declarations, adjust the schema-dependent fields, and copy or download the result.
What can you infer from one JSON sample?
For the sample below, id is observed as a number, active as a boolean, and name as a string. These are observations of one response. Another valid response could omit name or use null, so compare the output with the API contract before using the types.
{"id":42,"name":"Ada","active":true}
interface Root {
id: number;
name: string;
active: boolean;
}
type Payload = Root;How should you handle optional fields, nulls, and arrays?
If the API may omit name, review whether name?: string is appropriate. If the API permits an explicit null, review whether name: string | null is appropriate. The generator uses the first item to infer an array element type; an empty array provides no evidence about its elements. Inspect every permitted variant yourself.
Does a TypeScript interface validate an API response?
No. Generated interfaces describe compile-time expectations. An incoming network response still needs runtime checks when your application requires validation. Keep the API specification or a runtime schema as the source of truth.
What does the converter actually infer from these six inputs?
Checked on 2026-10-15 using this tool’s inference function in both Interfaces and Type aliases modes. The examples below show Interfaces output. Downloads preserve the exact generated text, including leading whitespace.
A sample describes observed values, not every valid API response. Adding more objects does not make this converter merge their fields or infer unions.
| Input case | What to review |
|---|---|
| Nested object | Nested properties create named declarations. |
| A second item omits name | name remains required even though the second item omits it. |
| Mixed array items | number[] describes only the first observed item; review it as (number | string | boolean)[] if that matches the contract. |
| Null is one observed type | null alone does not establish a nullable string. |
| No item shape to infer | unknown[] needs a schema or representative element shape. |
| Numeric ID exceeds safe integer range | JSON.parse changes 9007199254740993 to 9007199254740992 before inference. Use a source string identifier when the contract permits it. |
Nested object
Input
{"id":42,"owner":{"name":"Ada"}}Actual output
interface Root {
id: number;
owner: Owner;
}
interface Owner {
name: string;
}
type Payload = Root;A second item omits name
Input
[{"id":1,"name":"Ada"},{"id":2}]Actual output
interface RootItem {
id: number;
name: string;
}
type Payload = RootItem[];Mixed array items
Input
[1,"two",true]Actual output
type Payload = number[];Null is one observed type
Input
{"nickname":null}Actual output
interface Root {
nickname: null;
}
type Payload = Root;No item shape to infer
Input
{"items":[]}Actual output
interface Root {
items: unknown[];
}
type Payload = Root;Numeric ID exceeds safe integer range
Input
{"id":9007199254740993}Actual output
interface Root {
id: number;
}
type Payload = Root;What can go wrong?
| Problem | What to try |
|---|---|
| JSON parsing fails | Check quotes, commas, and brackets in the JSON Formatter. A JavaScript object literal is not necessarily valid JSON. |
| An empty array produces an unknown element shape | Use a representative nonempty sample, then check the type against the complete API schema. |
| A missing property is required in the result | Review other responses or the API contract and add the optional marker only when omission is allowed. |
| A large numeric ID changes digits | Quote identifiers at the source when the API contract defines strings. This generator uses ordinary JSON parsing, so large numeric values may already be rounded. |
Frequently asked questions
Does the generator upload my JSON?
No. JSON parsing and declaration generation happen in the current browser tab. Input is not added to the page URL.
Should I choose interfaces or type aliases?
Both can describe object shapes. Choose the style used by your project and review the resulting declarations; neither option adds runtime validation.
References
Added six checked inputs and outputs, with explicit first-item array inference and large-number precision limits.
First published .