About the Type Generator
You have a JSON response from an API and you need types for it. Writing them by hand is tedious for a 40-field payload, and it is error-prone in exactly the way types are supposed to prevent — a typo in a field name compiles fine and fails at runtime.
Paste the JSON, pick a language, get a type definition. Output is idiomatic for each ecosystem rather than a mechanical transliteration: Go gets struct tags, Java gets Jackson annotations, Kotlin gets Gson names, and Zod gets a runtime schema with the TypeScript type inferred from it.
When you'd use it
- Generating TypeScript interfaces for an API that has no published types.
- Creating Go structs with correct json tags for a service you are integrating.
- Producing a Zod schema so an API response is validated at runtime, not just at compile time.
- Bootstrapping model classes in Java, Kotlin, C#, or Swift from a sample payload.
- Deriving a JSON Schema from an example, to use for request validation or documentation.
One sample, two languages
The same input produces idiomatic output for each target, including the serialisation annotations each ecosystem expects.
JSON input
{
"id": 42,
"displayName": "Ada",
"tags": ["admin"],
"profile": { "timezone": "UTC" }
}TypeScript / Go
interface User {
id: number
displayName: string
tags: string[]
profile: Profile
}
type User struct {
ID int64 `json:"id"`
DisplayName string `json:"displayName"`
Tags []string `json:"tags"`
Profile Profile `json:"profile"`
}A sample is not a schema — read the output critically
Types are inferred from one example, and one example cannot tell you everything the API can return. Three things in particular need a human check.
- Optional fields. A field absent from your sample does not exist in the generated type. If the API omits fields for some records, add them and mark them optional.
- Nullability. A field that happens to hold a value in your sample is typed as non-null. If it can be null, the generated type is lying, and in a null-safe language like Kotlin or Swift that lie becomes a crash.
- Empty arrays. An empty array gives the generator no element to inspect, so it produces a permissive element type. Use a sample with populated arrays.
Numbers are the most common source of wrong output
JSON has one numeric type. Statically typed languages have many, and the generator has to guess from the sample value. A field holding 42 will be typed as an integer; if the same field can hold 42.5, the generated type will fail to deserialise.
The other failure is large identifiers. Values beyond about 9 quadrillion cannot be held exactly in a double, and languages that parse JSON numbers into 64-bit integers will handle them while JavaScript will not. If an id is large, treat it as a string on both sides.
Why Zod output is worth considering for TypeScript
A TypeScript interface is erased at compile time. It describes what you expect, and does nothing at all when the API returns something else — the mismatch surfaces later, somewhere unrelated, as undefined is not an object.
A Zod schema is a value that exists at runtime and can parse an unknown payload, either succeeding with a typed result or failing at the boundary with a message naming the offending field. The generator emits both the schema and the inferred type from a single definition, so there is nothing to keep in sync.
Naming
Nested objects need names, and the generator derives them from their parent key — a profile object inside User becomes UserProfile or Profile depending on the target language's conventions. Set the root name to something meaningful before generating; renaming afterwards means touching every nested type.
Field names are converted to each language's convention — camelCase for TypeScript and Kotlin, PascalCase for Go exported fields and C#, snake_case for Python — while the serialisation annotation preserves the original JSON key. That is why the annotations matter and should not be stripped.
Frequently asked questions
- Which languages are supported?
- TypeScript, Go, Python, Rust, Java, Kotlin, C#, Swift, plus Zod schemas and JSON Schema.
- Is my JSON uploaded?
- No. Parsing and code generation both run in your browser, so pasting a real production response is safe.
- Can I generate from several samples at once?
- Not directly — generation works from one document. For a field that varies across responses, merge the samples by hand into one document that includes every field you have seen, then generate from that.
- How are dates handled?
- JSON has no date type, so an ISO 8601 timestamp is just a string and is typed as one. Change it to your language's date type by hand and add whatever converter the deserialiser needs.
- Everything came out as a string. Why?
- Your sample probably came from a CSV conversion or a source that quotes all values. The generator can only work with the types present in the input.