Practical guide
How to generate TypeScript types from JSON
An API response sample can begin a data model, but it is not a complete contract. This guide explains how to obtain a working type and what cannot be inferred from one example before you use it in an application.
Generate a working Data alias
Paste one valid JSON document and select “Process”. Output always uses export type Data; the form has no alias-name setting. Copy the text into your own .ts file, rename it in your editor and check it with your project compiler before use.
Objects, arrays, strings, numbers, booleans and null can all be input roots. JavaScript code, comments and trailing commas are unsupported. The tool executes nothing, saves no file and fetches no API documentation. Resolve syntax errors with the JSON formatter first.
Check types in simple examples
The table shows exact output spelling. Member names are quoted, including spaces or Polish characters. String values, such as a date stored as text, infer string rather than Date. Numbers infer number, while null infers null rather than automatic optionality.
A type describes a value category, not the sample’s exact content: "Łódź" does not create a city enum, and 18 does not impose an age constraint. Compare copied output with API documentation, error examples and response variants before refining the model for your project.
| JSON | TypeScript |
|---|---|
{"city":"Łódź","active":true} | export type Data = {
"city": string;
"active": boolean;
}; |
[1,"a",null] | export type Data = Array<number | string | null>; |
[] | export type Data = unknown[]; |
{} | export type Data = Record<string, never>; |
Required members and unions instead of automatic merging
Every observed object member is required. An array of differing objects becomes a union of separate shapes rather than one object with optional members. Samples {"a":1} and {"b":"x"} do not establish that a and b are optional in every record; consult the contract.
Duplicate emitted type strings in an array are removed. Member order and nesting can nevertheless make similar structures produce different type text. Do not treat the variant count as all possible data states or the generator as a semantic type-normalization tool.
Empty containers and large numbers need decisions
An empty array produces unknown[] because it provides no evidence about future elements. An empty object produces Record<string, never>, an intentionally narrow model with no values under string keys. These are tool assumptions. Replace them when documentation permits later members or elements.
The token 9007199254740993 still infers number. A generated type guarantees neither JavaScript precision nor conversion to bigint. The same applies to amounts, identifiers and exponent notation. Agree representation with the API provider instead of assuming a declaration repairs precision lost during parsing.
Sample, validation and size boundaries
A TypeScript declaration does not check data received at runtime. This generator creates no JSON Schema, validator or business rules. Use separate checks for untrusted responses and project tests. An observed type does not establish that the next API response will have the same shape.
Input allows 50,000 UTF-16 units and 10,000 JSON values; output allows 500,000 units. Generation permits 32 container levels and 64 distinct emitted type shapes per array. The parser rejects duplicate names and unpaired Unicode surrogates. Exceeding a cap causes an error rather than a truncated type.
Privacy, copying and reset
Use a short anonymized sample instead of a complete production export. The tool processes input and output in the browser, without sending them to analytics or saving history in localStorage or sessionStorage. Loading the page still connects your device to hosting. Browser extensions and clipboard access remain outside this protection.
Editing a field clears the old result: select “Process” again to produce the current version. Copying is a separate action. Reset restores initial settings but cannot remove earlier clipboard copies, files or printouts. Report issues using a short synthetic example and expected result rather than confidential data.
Frequently asked questions
Does the generator create an interface?
No. It creates export type Data from the sample, including array and primitive roots.
Do dates become Date?
No. A date stored as text remains string. The generator does not guess string meanings.
Does output validate an API response?
No. Runtime checks and contract rules are separate requirements. The type is a review starting point.
Does reset remove copied output?
No. It resets the form; earlier clipboard copies, files or printouts need separate removal.
Sources and scope
Examples are synthetic and limits describe this implementation, not universal format requirements. Verify output in its destination system. This guide does not establish API, schema or business-rule compliance and is not a substitute for a security review.
Tools covered by this guide
JSON to CSV converter
Convert a flat JSON object array to CSV or TSV, with explicit rules for empty cells and formula-like text.
CSV to JSON converter
Convert CSV or TSV with a header to a JSON object array without guessing cell types.
JSON to TypeScript type generator
Infer a Data type declaration from a JSON sample, with array unions and explicit limitations.
Unix timestamp converter
Convert Unix seconds or milliseconds to UTC and Warsaw time, or an explicitly offset date to a timestamp.