How to use JSON to TypeScript
- Paste one JSON value or CSV sample and select its input format.
- Choose TypeScript, Zod, Go, Python or PHP, name the top model and choose how nulls are handled.
- Inspect the inferred fields, copy the models and check them against the real data.
Example: JSON to TypeScript
Infer types from a small order sample where one order carries an extra note.
Options
- Arrays
- Every item in an array is read and the types are joined into a union. Object items are merged, so a key that appears in only some items becomes optional. An empty array becomes unknown[] because nothing inside it can be read.
- Null and mixed values
- A null becomes part of a union, so a nickname that is null in the sample is written as string | null when a string also appears. Every JSON number becomes number, because JSON has one numeric type.
- Names and style
- The top name is used for the first type, and a nested type is named after that type and the property it came from. Interfaces and type aliases carry the same fields.
- Input and target
- Choose JSON or CSV and the target language. CSV values stay strings, including IDs with leading zeroes. TypeScript style and export controls apply only to their supported targets. Generated models describe the sample, so check them against real records before using them.
Supported inputs and limits
Where your input is processed
This tool processes your input in this browser. Your text and files are not uploaded to UseFreeTools. Check this tool's limits for anything it may save 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.