JSON to TypeScript, Zod & Go
Paste a sample API response or config file and get ready-to-use TypeScript types, a Zod validation schema, or Go structs with JSON tags.
Overview
Hand-writing types for an API response is slow and easy to get subtly wrong, especially for deeply nested payloads. This tool infers the types from real sample JSON: every nested object becomes its own named type, and objects with identical shapes share one definition instead of being repeated.
Arrays are analysed element by element rather than from the first item alone. A field that's missing from some objects in an array becomes optional, and a field that's sometimes null becomes nullable. Integers and decimals are told apart, which matters for Zod's .int() and Go's int64 versus float64.
The output is designed to compile without edits. Generated TypeScript passes the compiler's strict mode with the sample data assigned to it, the Zod schema parses the sample, and Go structs follow gofmt alignment with initialisms like ID and URL. Keys that aren't valid identifiers, such as created-at, are quoted in TypeScript and Zod and mapped with json tags in Go.
Examples & Sample Data
TypeScript from an array with an optional field
{"items":[{"sku":"A1","qty":2},{"sku":"B2","qty":1,"discount":{"code":"SAVE"}}]}
export interface Root {
items: Item[];
}
export interface Item {
sku: string;
qty: number;
discount?: Discount;
}
export interface Discount {
code: string;
}
Go structs with JSON tags
{"user_id":7,"avatarUrl":"https://example.com/a.png","score":9.5}
type Root struct {
UserID int64 `json:"user_id"`
AvatarURL string `json:"avatarUrl"`
Score float64 `json:"score"`
}
How It Works
- Paste sample JSON, ideally a real response that includes optional fields and array items.
- Choose TypeScript interfaces, TypeScript type aliases, a Zod schema, or Go structs.
- Set the name for the top-level type, such as Order or ApiResponse.
- Copy the generated code into your project. It updates as you edit the JSON.
Common Use Cases
Typing an API client
Paste a response from a third-party API to get TypeScript types for your fetch wrapper in seconds.
Validating untrusted input
Generate a Zod schema to check webhook payloads or form data at runtime, with the matching TypeScript type from z.infer.
Decoding JSON in Go
Get structs with json tags ready for encoding/json, instead of mapping every field by hand.
Tips & Best Practices
- Types can only be as complete as your sample. Include several array items, and responses where optional fields are both present and missing.
- Arrays that mix several types (for example numbers and strings) become unions in TypeScript and Zod, and any in Go.
- A field that's only ever null in the sample can't reveal its real type, so it becomes null or any. Edit it by hand once you know what it holds.
Frequently Asked Questions
No. Type inference and code generation run entirely in your browser, so private API responses never leave your device.
Every object in an array is compared. A key missing from any of them is marked optional (?: in TypeScript, .optional() in Zod, omitempty in Go). A key that's null in some samples becomes nullable (| null, .nullable(), or a pointer in Go).
It uses core APIs such as z.object, z.array, z.union, .optional(), .nullable(), and z.infer, which work the same in Zod 3 and Zod 4.
TypeScript has one number type. Go and Zod distinguish integers, so a field whose sample values are all whole numbers becomes int64 or .int(), and any decimal value makes it float64 or a plain z.number().
Related Tools
Explore more high-performance utilities.