How to use JSON to TypeScript
- Paste a JSON or CSV sample, or choose one UTF-8 source file. A selected file replaces the text. Choose the input format explicitly when automatic detection does not fit.
- For CSV, choose a delimiter and whether the first row contains names. Cells remain strings, including IDs with leading zeroes.
- Choose the output target, top type name and null handling. TypeScript style applies to TypeScript; the export option applies to TypeScript and Zod.
- Copy the generated source and review it against other real records before adding it to a project. Supply any target-language packages or runtime your project needs.
Example: JSON to TypeScript
Infer a root model, nested address and order type from the supplied JSON records.
Options
- Source format
- Automatic detection treats text beginning with { or [ as JSON. Otherwise, a comma or line break suggests CSV; a remaining valid JSON scalar is read as JSON and other text as CSV. Choose JSON or CSV explicitly when needed.
- CSV columns
- With headers enabled, the first row names fields; without them, names are column_1, column_2 and so on. Empty header names receive generated names. Repeated header names produce a warning and keep the last column of that name. All cells stay strings.
- Arrays and optional fields
- The tool examines every array item, combines observed types and merges object fields. A field missing from some object items becomes optional. Empty arrays have no observed item type, so the target uses an unknown or generic collection representation.
- Null handling
- Keeping them is the default, so observed nulls remain part of the type. The optional setting makes a null-bearing property optional and removes null from its type; a null-only property has no other observed type to infer. A single sample cannot establish which policy fits every record.
- Names and output style
- The top name supplies the first model name, with names derived for nested objects. TypeScript can use interfaces or aliases. Export prefixes apply to TypeScript and Zod only. Each other target uses its own supported type syntax and naming rules.
Supported inputs and limits
- Samples are limited to 1,000,000 characters, 30 levels and 200 named types.
- CSV allows 10,000 rows and 100 columns, with text cells; use JSON to infer numbers, booleans or nulls.
- Only observed values are inferred.
- Preserve nulls by default, or explicitly turn them into optional properties.
- Dates remain strings.
More details
Mixed types may become any in Go or mixed in PHP.
Unsupported Go JSON keys or PHP property names are refused rather than guessed.
Python output uses TypedDict and NotRequired, requiring Python 3.11 or later.
Zod output requires Zod in your own project; this page does not install it or validate your API.
Selected UTF-8 files replace the sample.
Existing TypeScript, Zod, Go, Python and PHP targets remain;
Java, C#, Kotlin and Rust targets are not added.
Where your input is processed
This tool does not upload your inputs. See the limits for anything saved on your device.
A sample is evidence, not a schema
Types inferred from one response describe that response only. A field that is absent from the whole sample, a value that is null only on other records, or a number that arrives as a string from another endpoint will not appear in the output. Treat the result as a starting point: check it against the real records, then tighten the optional flags and unions by hand.
Questions about JSON to TypeScript
Why is a property marked optional?
It appeared in some items of an array and not others. Marking it optional keeps the type true for every item in the sample, and you can tighten it later once the real records are known.
Why is my date a string?
JSON has no date type, so a date arrives as text. The converter writes string and leaves the conversion to your own code.
What happens with an empty array?
There are no items to infer from, so the target uses its unknown or generic collection type. PHP needs at least one object to generate a class.
Does this call my API or upload my data?
No. The sample is parsed and converted in this browser. This page does not call your API or upload the sample.