JSON to TypeScript
Types from a JSON sample
JSON
Generated types
Paste some JSON to generate its types.
About this tool
This tool turns a JSON sample into TypeScript types you can paste straight into your code. It is mainly useful for typing the response of an API you consume, a configuration file or test fixtures, without writing every interface by hand or missing a field that is nested three levels deep.
Each nested object gets its own type, named after its key, and identical structures share the same name. In an array of objects, a key missing from some items becomes optional and null values are added to the type. You choose between interface and type, set the root type name, toggle export and readonly, and a separate tab offers the equivalent Zod schema.
How to use it
- Paste your JSON into the “JSON” field, or click “Sample” to try it out.
- Fill in “Root type name” and pick interface or type under “Declaration”.
- Check “Add export” or “Read-only properties (readonly)” to match your conventions.
- Under “Generated types”, switch from the “TypeScript” tab to “Zod schema” if needed.
- Click “Copy” or “Download” to get the types.ts or schema.ts file.
Frequently asked questions
How does the tool detect optional properties?
It merges every object in the same array. A key that appears in only some items is marked optional with ?, or .optional() in Zod. A key that is sometimes null gets | null. The more representative your sample, the more accurate the types.
Is my JSON sent to a server?
No. Parsing and type generation run in your browser. The JSON you paste is neither sent nor saved; only your settings, such as the root type name or the interface versus type choice, are remembered locally in this browser.
What if my JSON is invalid?
The tool shows “Invalid JSON” with the line and column of the error, and displays the faulty line with a marker under the offending character. Fix it in the field and the types update automatically as you type.
How do I use the generated Zod schema?
Install the zod package in your project, then paste the code: each object has its own schema, defined before it is used, and the root type is inferred with z.infer. You can then validate an API response at runtime with schema.parse().