JSON to TypeScript / Go / Rust Struct Generator
Paste JSON, pick a target language, get an idiomatic type definition. Supports TypeScript, Go, Rust, Kotlin, Java, C#, and Python TypedDict. Powered by quicktype, runs in your browser.
- Paste a representative JSON sample into the left textarea.
- Pick the target language from the Target dropdown.
- Click Generate. First click loads the engine (~2–3 seconds on a 4G connection); subsequent generations are instant.
- Copy the result, or download it as the right file extension.
What does it do?
Generates idiomatic types in your target language by inferring the schema from one or more JSON samples. Field types are inferred — strings stay strings, numbers become the language’s numeric type, booleans become bool, arrays become slices/lists/arrays, nested objects become nested types. Optional fields (those that are sometimes null or missing across samples) are marked as nullable in the output. Powered by quicktype-core, the same engine behind quicktype.io.
Example
JSON input:
{
"name": "Ada",
"age": 36,
"active": true,
"tags": ["math", "logic"]
} TypeScript output (target = TypeScript, type name = User):
export interface User {
name: string;
age: number;
active: boolean;
tags: string[];
} Common pitfalls and how to handle them
Type inference from JSON has fundamental limits — JSON does not carry enough information to fully constrain a type system. The patterns below cover where the inferred type may not match what you want.
- Optional vs. required from a single sample. A single JSON object cannot tell the generator which fields are optional. Provide multiple samples (paste a JSON array of representative objects) so the generator can mark fields that are sometimes missing as optional.
- Empty arrays. `{"items": []}` produces an array of `any` — the generator has no element to infer from. Include at least one populated example, or fix the type by hand after generation.
- Heterogeneous array elements. A JSON array `[1, "two"]` becomes a union type — the result may not be ergonomic in some target languages (Go especially). If the array is supposed to be homogeneous in your real data, fix the sample.
- Date strings. JSON has no Date type. ISO 8601 date strings are inferred as `string`. quicktype can sometimes detect them as Date in TypeScript output — adjust by hand if you want stronger typing.
- Numeric IDs that lose precision. JSON numbers > 2^53 (large 64-bit IDs) lose precision when parsed by JavaScript. The generated TypeScript type uses `number` regardless. For 64-bit precision, use `string` in your JSON or migrate to a `bigint` type by hand.
- Underscored vs. camelCased fields. The generator preserves the JSON field naming. If your JSON uses snake_case but the target language expects camelCase, the output uses snake_case fields with serde/json annotations where applicable. Override by post-processing or using quicktype CLI flags.
Frequently asked questions
Why is the first Generate slow?
The quicktype engine bundle is around 465 KB gzipped. It loads on the first Generate click, which takes 2–3 seconds on a 4G connection. After that the module is cached for the rest of the page session — and the browser caches it across visits, so subsequent first-clicks are also instant unless the cache has been cleared.
Can I generate from multiple JSON samples?
Wrap your samples in a JSON array and paste the array. The generator infers the union of fields seen across samples and marks fields as optional when they are missing from at least one. This is the right way to ensure your generated types tolerate the variation in real data.
Which language should I pick for backend code?
Match what your project already uses. Go output uses standard struct tags for `encoding/json`. Rust uses serde derives. Kotlin uses kotlinx.serialization annotations. Java produces POJOs compatible with Jackson. The choice is project-specific, not preference-based.
Are field comments preserved?
JSON has no comment syntax, so there are no comments in the input to carry over. quicktype can include doc comments in the output for some languages — these are auto-generated descriptions, not user content.
Is my JSON uploaded?
No. Everything runs in your browser — your input is processed locally by the quicktype-core JavaScript module on this page. quicktype-core itself loads from the same origin (this site’s static asset host); no third-party server sees your data.
How big a JSON sample can I use?
Up to about 5 MB of JSON before the generator starts to take noticeable time. The generator is designed for representative samples, not full datasets — typically a handful of objects is plenty to infer a clean schema.