JSON to types (TypeScript, Go, Python, Zod)
json_to_typesGenerate TypeScript interfaces, Go structs, Python dataclasses, and Zod schemas from a JSON sample, merging array items so missing keys become optional and nulls become nullable.
Instructions
Generate type definitions from a JSON sample: TypeScript interfaces (or type aliases), Go structs with json tags (initialisms like ID/URL, pointers for optional/nullable, optional omitempty), Python dataclasses (snake_case fields with the original key noted) and Zod schemas. All items of an array are merged into one type (missing keys become optional, null makes a field nullable, int+float → number/float64, mixed values → unions); identical shapes share one name. These four are every language the website supports. Give "text" or a file "path". Web version: https://s3eidat.github.io/json-to-types/
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Or: a path to a JSON file (UTF-8; use this for big inputs). | |
| text | No | The JSON sample as inline text. | |
| export | No | TypeScript / Zod: add the export keyword. | |
| output | No | Optional: write the code to this file (with language "all", the four outputs joined by headers). | |
| language | No | Output language, or "all" for all four. | typescript |
| rootName | No | Name of the top-level type (turned into PascalCase). | Root |
| goOmitEmpty | No | Go: add ,omitempty to optional fields. | |
| tsTypeAlias | No | TypeScript: use "type X = {…}" instead of "interface X {…}". |