JSON to Types
Generate TypeScript, Zod, JSON Schema, C#, Go or Python types from JSON.
How to use the JSON to Types
- 1Paste a JSON sample.
- 2Pick a target: TypeScript, Zod, JSON Schema, C#, Go or Python.
- 3Copy or download the generated types.
About JSON to Types
JSON to Types reads a JSON sample and generates matching type definitions for TypeScript, Zod, JSON Schema, C#, Go or Python. Nested objects become their own named types, arrays of objects are merged into a single item type, and keys that are missing in some array items can be marked optional. ISO dates such as 2024-03-18 can be detected and mapped to native date types where the language has them.
Each target has its own settings. TypeScript output uses interface or type, with optional export and readonly properties. Zod schemas can export inferred types. C# classes get a namespace, JsonPropertyName attributes and nullable reference types if you like. Go structs can use omitempty and pointers for nullable fields, and Python output is available as dataclasses, TypedDict or Pydantic models. JSON Schema follows draft 2020-12.
The JSON to TypeScript converter saves you from typing interfaces by hand when you integrate a third-party API, read a webhook payload or document a config file. Paste a real response, generate the types, then refine names and optional fields before you commit them.
Frequently asked questions
How accurate are types generated from a JSON sample?
They describe exactly what the sample contains. If a field can also be null, missing or a different type in other responses, the sample can't show that, so paste several representative items in an array or adjust the result by hand.
What is Zod?
Zod is a TypeScript library that checks data at runtime against a schema, for example an API response. With z.infer the TypeScript type is derived from the schema, so validation and types never drift apart.
Should I use interface or type in TypeScript?
For plain object shapes both work the same. Interfaces can be extended and merged across declarations, while type aliases can also express unions and mapped types. Many teams simply pick one style and stay consistent.
What happens to a key that is always null?
A value that is only ever null doesn't reveal its real type, so the generator can only type it loosely. Replace it with the actual type, such as string or number, once you know what the API sends.
More in Developer Tools
Generate strong passwords and memorable passphrases.
Create QR codes for links, Wi-Fi and contacts with custom colors.
Get lorem ipsum and realistic test data as JSON, CSV or SQL.