Turn JSON into typed models
Generate classes, records and structs from a sample payload. Pick a language and the root name.
7 languages0 bytes uploaded
Input
Result
What each language gets
| Language | Output | Options |
|---|---|---|
| Java | record or POJO | Jackson or Gson annotations, Lombok @Data, @Getter/@Setter and @Builder, ignore unknown fields, package |
| Kotlin | data class | kotlinx.serialization, Moshi, Gson or Jackson; val or var; package |
| TypeScript | interface, type alias or Zod schema | export, readonly |
| Python | Pydantic model, dataclass or TypedDict | 3.10+ syntax (list[str], int | None) or typing.List/Optional |
| Go | struct with json tags | pointers for optional fields, omitempty, any or interface{}, package |
| C# | class or record | System.Text.Json or Newtonsoft.Json attributes, nullable reference types, namespace |
| Rust | struct with serde derives | Debug, Clone, PartialEq; rename_all = "camelCase"; skip None |
Options stay as you set them while you switch languages, and the result updates as you change them.
How types are inferred
- Numbers
- Whole numbers become
int(longabove 2,147,483,647). Any number with decimals becomesdouble, and an array that mixes both, like[1, 2.5], becomes a list of doubles. - Arrays of objects
- Every item is merged into one type, so the class gets the union of all the keys it sees.
- Missing keys
- A key that appears in some items and not in others is optional:
note?: stringin TypeScript, a nullable orOptiontype elsewhere. - null
- A
nullin some items makes the field nullable. A key that isnulleverywhere carries no type at all, so it becomesObject,unknown,Anyorserde_json::Value. - Mixed types
- If the same key holds a string in one item and a number in another, the field falls back to that same catch-all type.
- Nested objects
- Each one becomes its own class, named after its key in PascalCase. Keys of arrays are made singular:
ordersgivesOrder,categoriesgivesCategory. Two classes with the same name get a number (Address2). - Dates
- Stay strings. The converter does not guess formats; change the type yourself if you want
Instant,LocalDateordatetime.
Field names and annotations
JSON keys are often not valid names in your language: full-name, 2fa, class. The converter writes the idiomatic name for each language (camelCase for Java and Kotlin, snake_case for Python and Rust, PascalCase for Go and C#) and maps it back to the original key with the annotation your library expects. Reserved words get an underscore, so class becomes class_.
public record User(
@JsonProperty("full-name") String fullName,
@JsonProperty("class") String class_
) {}type User struct {
FullName string `json:"full-name"`
Class string `json:"class"`
}TypeScript keeps the original keys and quotes them where needed ("full-name": string), because the type has to match the object that JSON.parse returns.
Getting a good result from your sample
The converter only knows what your sample shows. A few minutes spent on the sample saves more time than fixing the classes afterwards:
- Use a real response, not one typed from memory. Copy it from your browser's network tab or from
curl. - Show the variation. Put two or three items in each array, including one with the optional fields, so the converter can tell what is optional.
- Replace nulls you can type. If you know
deletedAtis a date string when present, give it a value in the sample. - Write decimals as decimals. A price of
10is typed as an integer;10.5is typed as a double. - Trim long arrays. Three items teach the converter as much as three thousand.
- Review before you commit. Money usually wants
BigDecimalorDecimal, IDs may want strings, and string fields with a fixed set of values may want an enum.
Language guides
For the decisions the converter cannot make for you, read JSON to Java: records, POJOs, Jackson and Gson and JSON to TypeScript: interfaces, types and Zod.
If the converter says your input is invalid, paste it into the formatter: its status line points at the problem.