JSON to Code Generator
Paste JSON, get model classes for Python, Kotlin, Swift, Dart, Rust and 19 more.
One JSON document, or several samples one after another or one per line (JSON Lines). Comments and trailing commas are ignored. Your data stays in this browser.
Type inference
To use it
Notes
About the JSON to Code Generator
Paste a JSON response — or several, one after another — and get model types for your language: Python dataclasses or Pydantic v2 models, Kotlin data classes for kotlinx.serialization, Jackson or Klaxon, Swift Codable structs, null-safe Dart classes with fromJson/toJson, Rust structs for serde, C++ for nlohmann/json, plus PHP, Ruby, Crystal, Objective-C, Elixir, Elm, Haskell, Scala 3, JavaScript, Flow, PropTypes, Effect Schema and JSON Schema. TypeScript, Zod, Go, C# and Java are here too, with the defaults of their dedicated pages.
Types are inferred with quicktype from every sample, so a field missing from one response becomes optional and one that is sometimes null becomes nullable. You can also start from a JSON Schema. Everything runs in your browser, in a background worker.
How to use it
- Paste JSON or a JSON Schema, open a .json file, or press Load sample. Several samples (or JSON Lines) give better types.
- Pick the Language and set the Root type name, for example
Booking. Nested types are named after their property. - Choose the language options — the Python style and version, Kotlin’s serialization library, Swift
structorclass, Rust derives, the C++ namespace, a package or module name. - Read To use it under the code: it says which library or plugin the code needs and the line that parses your JSON.
- Copy the code or download the file; outputs with several files (Objective-C, multi-file Swift or C++) have Download all (.zip).
Examples
{"bookingId": "BK-1", "createdAt": "2026-10-03T09:41:00Z", "notes": "Late check-in"}
{"bookingId": "BK-2", "createdAt": "2026-10-03T11:05:12Z"}class Booking(BaseModel):
model_config = ConfigDict(populate_by_name=True)
booking_id: str = Field(alias="bookingId")
created_at: datetime = Field(alias="createdAt")
notes: str | None = NoneRoot type Booking, Pydantic v2 models, Python 3.10. notes is missing from the second sample, so it defaults to None; the aliases keep the JSON key names. Parse with Booking.model_validate_json(text).
{"bookingId": "BK-1", "nights": 3, "paid": true}@Serializable
data class Booking (
val bookingId: String,
val nights: Long,
val paid: Boolean
)Decode with Json.decodeFromString<Booking>(text) once the serialization plugin is applied.
{"bookingId": "BK-1", "guest": {"firstName": "Meera"}}#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Booking {
pub booking_id: String,
pub guest: Guest,
}rename_all = "camelCase" maps the snake_case fields to the JSON keys.
Common uses
- Typing an API response in a Flutter, Android or iOS app before writing the network code.
- Getting Pydantic models or dataclasses for a webhook payload in a FastAPI or Django service.
- Generating serde structs, nlohmann/json bindings or Scala case classes for a JSON config or message format.
- Turning a JSON Schema from an API spec into models for several languages at once.
What the generated code needs
- Python: dataclasses use the standard library, plus python-dateutil when dates are parsed; Pydantic models need Pydantic 2.
- Kotlin: the kotlinx.serialization plugin and kotlinx-serialization-json, or jackson-module-kotlin, or Klaxon.
- Swift, Objective-C: Foundation only.
- Dart: dart:convert only (freezed and json_serializable when you choose them).
- Rust: serde with the derive feature and serde_json.
- C++: nlohmann/json 3 and C++17 (or Boost).
- PHP 7.4+, Crystal: no packages. Ruby: dry-struct and dry-types. Elixir: Jason. Elm: elm/json and NoRedInk/elm-json-decode-pipeline. Haskell: aeson. Scala 3: circe or upickle.
- JavaScript and Flow: none; PropTypes: prop-types; Effect Schema: effect 3.
The exact parse call for your root type is shown under the code.
Checked by compiling and running
We compiled the code generated for this page’s sample and used it to read both sample documents and write them back: Python 3.14 (dataclasses and Pydantic 2.13), Kotlin 2.4 (kotlinx.serialization 1.9, Jackson 2.18, Klaxon 5.6), Swift 6.4, Dart 3.13, Rust 1.98 with serde, C++17 with nlohmann/json 3.11, Objective-C (clang and Foundation), PHP 8.5, Ruby 4.0 with dry-struct, Crystal 1.21, Scala 3.7 (circe 0.14 and upickle 4.3), JavaScript and Flow in Node.js, and TypeScript with Zod 4 and Effect 3 under tsc --strict. The Elm module was compiled with Elm 0.19.2. Haskell and Elixir output was not compiled in these checks.
That testing found and fixed problems in quicktype’s own output: its Pydantic mode builds models with positional arguments, which Pydantic rejects, so the Pydantic models here are generated from the inferred schema instead; the PHP reader now tolerates missing optional keys; and the kotlinx.serialization and Objective-C usage comments use the current API names.
How the types are inferred
- A property missing from at least one sample (or one array item) is optional; one that is
nullin some samples is nullable. - A string property becomes an enum only when it has at least 10 values in your samples and fewer distinct values than the square root of that count. Turn off Detect enums to keep plain strings.
- Objects whose keys look like data (IDs, dates) become maps; objects with mostly the same properties are merged into one type.
- ISO 8601 date-time strings become date types (turn off Date strings → date types to keep strings); UUID detection is off by default.
- JSON Schema input never downloads anything: references must point inside the schema.
Limitations
- Types are only as good as the samples: a field seen once as a string is typed as a string even if the API can also send a number. Paste several real responses.
- C (cJSON) is not offered: quicktype’s C output depends on helper headers (list.h, hashtable.h) that are not part of cJSON.
- TypeScript, Zod, Go, C# and Java use their dedicated pages’ defaults here; those pages have the full set of options.
- Very large inputs (several megabytes) are generated when you press Generate rather than as you type, and generation stops after 30 seconds.
Privacy
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
Is my JSON uploaded?
No. The generator runs in your browser, in a background worker, and the page works offline once it has loaded. Nothing you paste or open is sent to a server.
Dataclasses or Pydantic?
Dataclasses with from_dict/to_dict need nothing but the standard library (and python-dateutil for dates) and check every value with assert; they write dates back with isoformat(), so 2026-11-14 comes back as 2026-11-14T00:00:00. Pydantic v2 models validate with clear error messages, keep dates as dates, convert UUIDs and work directly with FastAPI. Choose Dataclasses only if you just want the type declarations.
Why is my field called booking_id when the JSON says bookingId?
Each language gets its own naming style: snake_case in Python, Rust, Ruby and Elixir, camelCase in Kotlin, Swift and Dart. The JSON key is kept through an alias, @SerialName, CodingKeys, rename_all or the decoder, so reading and writing JSON still uses the original names.
Which language versions does the code need?
Python 3.7 or later for dataclasses (pick your version — 3.10 writes X | None); Pydantic 2 needs Python 3.9 for the latest release. Dart output is null-safe (2.12+), C++ needs C++17 unless you choose Boost, and PHP needs 7.4+ for typed properties.
Can I generate several files at once?
Objective-C always gives a .h and a .m file, and Swift and C++ can put each type in its own file. Pick a file in the list to see it, or download them all as a ZIP.