Tool guide
About this tool.
Typed languages need a declared shape for every JSON payload they read. This generator reads a JSON sample and writes the matching Go structs, Rust structs, Kotlin data classes, Java records, C# classes, Python dataclasses or Swift Codable types, so you start from working declarations instead of typing them by hand.
Records in one array are merged into a single item type. A property missing from some records, or holding null in some of them, becomes optional: a pointer with omitempty in Go, Option in Rust, a nullable with a null default in Kotlin and Python, a boxed type in Java, a nullable property in C# and an optional in Swift. Nested objects get their own named types, such as UserProfile.
The declarations describe one sample, not a contract. Check optional fields, numeric widths and untyped values against the API documentation before shipping them.
- Model an API response, webhook payload or configuration file in Go, Rust, Kotlin, Java, C#, Python or Swift from a real example.
- Paste several records as one JSON array to discover optional and nullable fields before they cause deserialization errors.
- Draft the types for a client library, then rename fields, narrow strings to enums and add validation in your own code.
Paste a JSON object or an array of objects, or apply a sample. To merge several records, supply them as one JSON array. The output updates as you type.
Pick the target language and name the root type. Choose whether optional means missing or null in some records, or every property. For Python, choose dataclasses or Pydantic models.
Review the declarations: the root type comes first and nested types follow in the order they appear. Python lists nested classes first so each one is defined before use.
Copy the code, send it to the scratchpad or save it as types.go, types.rs, types.kt, types.java, types.cs, types.py or types.swift.
- {"id":1,"name":"Ada"} with Go → type Root struct { Id int64 `json:"id"`; Name string `json:"name"` }
- [{"id":1,"email":"[email protected]"},{"id":2}] with Rust → pub email: Option<String>, because the second record has no email.
- {"a/b":1} with Kotlin → @SerialName("a/b") val aB: Long, with the original key kept in the annotation.
- {"type":1,"class":2} with Java → record components type and class_, because class is a reserved word.
- {"nick":null} with C# → public object? Nick { get; set; }, because null alone shows no type.
- {"profile":{"active":true}} with Python → class UserProfile first, then class User with profile: UserProfile.
- {"id":1} with Swift → struct Root: Codable { let id: Int }, plus CodingKeys only when a key is renamed.
- Generation is local. The JSON is parsed in the browser or editor and never uploaded or executed.
- The root must be a JSON object with at least one property or an array of objects. A scalar, an empty object or an array holding scalars or null has no fields to declare and is rejected.
- Inference reflects only the supplied sample. A field present in every record becomes required even if your API documents it as optional.
- Whole numbers become 64-bit integers and other numbers become double precision floats. Strings stay strings: dates, emails and IDs are not narrowed.
- Values with mixed kinds, null-only values, empty objects and arrays holding null or mixed items collapse to the catch-all type of the language; unions are not generated.
- Field names are converted to the naming style of the language with accents removed, and a repeated name gets a numeric suffix. Renamed keys keep the original in an annotation or comment. A C# property that would repeat its class name gets a Value suffix.
- Go encoding/json cannot map a key that contains a comma, so such a field gets an explaining comment and the tag json:"-". The key - is written as json:"-,".
- Untyped values use Any in Kotlin, which kotlinx.serialization cannot serialize; replace it with JsonElement. Python output uses list[...] and X | None annotations, which need Python 3.10 or later.
- Imports or using lines are added for the serialization library each language commonly uses: serde, kotlinx.serialization, Jackson, System.Text.Json, dataclasses or Pydantic.
- Limits: 1,000,000 input characters, 200,000 JSON values and properties, 64 nesting levels and 1,000,000 output characters. Larger input is rejected, never truncated.
- A duplicate key in the JSON keeps its last value, as JSON.parse does, and the summary names the key and line.
- A number beyond the range of a double, such as 1e400, or one that would become 0, such as 1e-400, is rejected.
- Java output declares every record public, so keep each record in a file named after it; the single downloaded file holds them all and must be split before javac accepts it.