About JSON to TypeScript & Go Types
Paste a sample API response and this tool writes the types for it: TypeScript interfaces, Go structs with json tags, Python dataclasses and a JSON Schema (draft 2020-12). It saves typing out a large payload by hand and catches fields you would have missed.
Types are inferred from every value in the sample. All items of an array are merged, so a field that is missing from some items becomes optional (coupon?: in TypeScript, omitempty in Go, = None in Python), and a field with different types becomes a union (string | number) or any in Go with a comment. Nested objects become named types, using the key in PascalCase and singular for array items (orders gives Order). Whole numbers become int64 in Go and int in Python, others float64 and float. Go field names follow Go style, with initialisms such as ID and URL.
How to use it
- Paste JSON on the left, or click Load sample.
- Set the root type name, then pick a language tab.
- For TypeScript choose
interfaceortypeand whether properties arereadonly; for Go choose whether nullable fields become pointers. - Copy the code or download it.
Examples
- Generate types for a user with orders: gives
RootandOrder, withcouponoptional. - See a nullable field:
nullalone can't tell the type, so it staysnull/any.
Common questions
How accurate are the types?
They describe the sample, not the API contract. Paste several representative responses inside one array so optional and nullable fields show up.
Which Python version do the dataclasses need?
Python 3.10 or later, because they use str | None and list[str].
Why is a number typed as float64?
At least one value had a decimal point or exponent, such as 20.0 or 1e3.
Related tools
- JSON Formatter & Validator: find syntax errors first.
- YAML to JSON Converter: generate types from a YAML config.
- cURL to Code Converter: turn the request into code too.