How should you check the result?
Test a second response that omits a field or supplies null before accepting generated types. Array inference uses the first element; heterogeneous arrays require manual review. A declaration does not validate an HTTP response at runtime.
Inference is a starting point, not a schema
Use the generated declarations to bootstrap code from a representative payload. Use OpenAPI, JSON Schema, or a hand-maintained domain model when optionality, validation constraints, and unions must be authoritative.
How do you use it?
- Paste a representative JSON object or array into Input.
- Choose Interfaces or Type aliases and select Convert.
- Review nested declarations and manually add optional properties or unions that the sample cannot prove.
Worked example
Infer a nested object shape
Input
{"id":42,"owner":{"name":"Ada"}}Output
interface Root {
id: number;
owner: Owner;
}
interface Owner {
name: string;
}
type Payload = Root;The generator names nested declarations from property names and infers primitive types from the supplied values.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| A field absent from later records is still required. | Only the first array item supplies the inferred item shape. | Review all valid responses and mark the field optional only if the API contract permits omission. Adding more records alone does not change this generator’s inference. |
| A mixed array is generated as number[]. | The first item is numeric, so the generator does not discover later string or boolean items. | Review and replace the inferred item type with the required union, or use the authoritative schema. |
| A long numeric identifier cannot be represented exactly. | Ordinary JSON parsing uses JavaScript numbers and can round integers above 9,007,199,254,740,991. | Use a quoted identifier at the data source when the contract specifies a string. Quoting an already rounded value cannot recover lost digits. |
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. |
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;Important behavior of JSON → TypeScript
Inference reflects the sample only; optional fields and unions require real schema knowledge.
Standards and implementation references
- TypeScript Handbook — Object Types (opens in a new tab)Explains interfaces, optional properties, arrays, and structural typing.
- RFC 8259 — JSON (opens in a new tab)Defines the source value types available for inference.
Frequently asked questions about JSON → TypeScript
Does this converter detect optional fields across array items?
No. It inspects the first array item. In [{"id":1,"name":"Ada"},{"id":2}], name is still generated as required. Review the API contract and add ? manually when omission is valid.
What types are generated for null and empty arrays?
A null value produces the null type, not an inferred string | null union. An empty array produces unknown[] because there is no element shape to inspect.
Does the generated interface validate incoming JSON?
No. Interfaces and type aliases provide compile-time declarations. Add runtime validation at the application boundary when incoming data needs checking.
Are JSON values uploaded or preserved losslessly?
Input is processed locally and is not placed in the URL. This generator uses ordinary JSON.parse, so large numeric values can be rounded before inference. Local processing does not mean lossless parsing.
What changed?
Checked six input cases in both declaration modes and published actual outputs, including first-item array inference, null, empty arrays, and numeric-ID precision limits. October 15, 2026: added result checks and specific capability boundaries.