How to use JSON to TypeScript, Zod, Pydantic and Go
- Paste a JSON sample, such as an API response.
- Pick the output: TypeScript, Zod, JSON Schema, Pydantic or Go, and name the root type.
- Copy the generated code or download it as a file.
Types from real data
Writing types by hand for an API response is slow and error-prone: a field that is sometimes missing, a value that is occasionally null, a number that is usually whole but sometimes not. Paste a real sample and this tool infers the types for you, then writes them in the language you need: TypeScript interfaces, Zod schemas that validate at runtime, a JSON Schema for validators and OpenAPI, Pydantic models for Python, or Go structs with JSON tags.
Nested objects become their own named types, named after their keys: an orders array produces an Order type, addresses an Address. Arrays of objects are merged, so if you paste an array of several records, a key that appears in only some of them is marked optional, and a value that is null in some is marked nullable. The more varied your sample, the more accurate the result.
Formats, not just strings
Strings are checked for common formats. ISO dates and date-times, email addresses, web addresses and UUIDs are recognised, and each output uses its own way of expressing them: z.email(), z.url(), z.uuid() and z.iso.datetime() in Zod 4; format keywords in JSON Schema; datetime, date and UUID types in Pydantic; and time.Time in Go. Whole numbers become integers where the language distinguishes them.
Idiomatic output
Each language follows its own conventions. Pydantic fields use snake_case with aliases to the original JSON keys, so createdAt becomes created_at but still reads and writes createdAt, and Python keywords such as class become class_. Go fields are exported in PascalCase with ID and URL capitalised, optional and nullable fields become pointers, and omitempty is set where a key can be missing. Keys that aren't valid identifiers, such as first-name, are quoted in TypeScript and Zod.
Treat the output as a strong first draft: a sample shows what a response can look like, not everything it might contain, so review enums, optional fields and number types against the API's documentation.
Private
API responses often include personal data, internal IDs and tokens. Inference and code generation happen in your browser; nothing you paste is uploaded or stored.
Questions
- How are optional fields decided?
- From your sample. When an array holds several objects, a key missing from some of them becomes optional, values that are null in some become nullable, and numbers that are whole in some and fractional in others become a general number. The more varied the sample, the more accurate the types.
- Does it detect dates, emails and IDs?
- Yes. Strings that look like ISO dates and date-times, email addresses, web addresses and UUIDs get matching formats: z.email() and z.iso.datetime() in Zod, format keywords in JSON Schema, datetime and UUID in Pydantic, time.Time in Go.
- Is my JSON uploaded?
- No. API responses often contain personal data and tokens, so the types are inferred in your browser and nothing is sent or stored.