{}JSONFiddleEditor
Tools/

Type Generator

Generate TypeScript, Go, Kotlin, Rust types or JSON Schema from JSON.

Generate typed code from JSON in 15 languages via `quicktype`

Manually writing TypeScript interfaces, Go structs, or Kotlin data classes from a JSON payload is tedious and error-prone. This tool sends your JSON sample to a protected JSONFiddle API route that runs quicktype-core — the same engine behind the quicktype CLI — with strict body limits, language allowlists, and execution timeouts. It infers types from the structure and values of your data: strings, numbers, booleans, nullable fields, arrays of homogeneous types, and nested objects all map to idiomatic types in the target language. You get TypeScript interfaces, Python dataclasses, Rust structs with serde derives, Go structs with json tags, Java POJOs, Kotlin data classes, and 9 more. Do not submit secrets or production-only payloads to server-side tools.

How to generate types

  1. 1Paste a JSON sample into the left editor. The richer the sample, the better the inferred types.
  2. 2Select a target language from the dropdown (TypeScript, Go, Rust, Python, etc.).
  3. 3Click "Options" to expand per-language settings — e.g., "Interfaces only", "Derive Debug", "Package name".
  4. 4Click Generate. The typed output appears on the right, ready to copy into your project.
  5. 5For JSON Schema, select "JSON Schema" as the language and choose a schema version.

Under the hood

  • `quicktype-core` inference engineAnalyzes JSON values to infer types: merges array element types into unions, detects optional fields across multiple samples, and maps JSON primitives to language-native types.
  • 15 target languagesTypeScript, JavaScript, Python, Java, C#, Go, Rust, Kotlin, Swift, Dart, Ruby, Haskell, C++, Elm, and JSON Schema. Each has its own renderer with idiomatic output.
  • Per-language renderer optionsFine-grained control: TypeScript can emit types vs interfaces, Rust can toggle Debug/Clone/PartialEq derives, Java can enable Lombok, Swift can set access levels, and more.
  • JSON Schema generationA separate codepath (not quicktype) walks the JSON structure and emits a schema with $schema, type, properties, required arrays, and items for arrays. Supports draft-04 through 2020-12.
  • Server-side generation with limitsThe JSON sample is posted to /api/generate-types so quicktype can run server-side with body-size caps, language and renderer allowlists, execution timeouts, and generic error responses.

Real-world scenarios

  • API client scaffoldingPaste an API response, generate TypeScript interfaces, and drop them into your codebase. Type-safe API consumption in seconds.
  • Cross-language portingWorking on a Go service that consumes the same JSON as a TypeScript frontend? Generate both from the same sample to keep them in sync.
  • JSON Schema for validationGenerate a JSON Schema from a sample payload, then use it with ajv, Zod, or any schema validator to enforce structure at runtime.
  • Rust serde boilerplateGenerate Rust structs with #[derive(Serialize, Deserialize)] and serde attributes instead of writing them by hand.
  • Learning unfamiliar languagesSee how a data structure looks in Kotlin, Haskell, or Elm without knowing the language's type syntax by heart.

JSON to TypeScript

// Input JSON:
{
  "user": {
    "id": 1,
    "name": "Alice",
    "tags": ["admin", "user"],
    "address": { "city": "New York", "zip": "10001" }
  }
}

// Generated TypeScript (interfaces only):
export interface Root {
  user: User;
}

export interface User {
  id:      number;
  name:    string;
  tags:    string[];
  address: Address;
}

export interface Address {
  city: string;
  zip:  string;
}

Questions

How does quicktype infer optional vs required fields?

From a single JSON sample, all fields present are marked required. If you provide multiple samples (e.g., an array of objects where some lack a field), quicktype detects the optional fields and marks them accordingly.

What is the difference between the JSON Schema output and quicktype's schema?

The JSON Schema option uses a custom codepath that directly maps JSON structure to a schema document. It does not go through quicktype's inference pipeline. This gives you a clean, minimal schema you can use with validators like ajv.

Can I generate types for deeply nested JSON?

Yes. quicktype handles arbitrary nesting depth. Each nested object becomes its own named type/interface/struct, and relationships are expressed through composition.

Why does the output differ from the quicktype CLI?

The browser version uses quicktype-core (the library), which is the same engine as the CLI but invoked programmatically. Minor differences can occur due to renderer option defaults, but the type inference logic is identical.

Related tools