What it does
Writing types for an API response by hand is slow and error-prone. Paste a real response and the tool works out the structure: nested objects become their own types, and arrays are analysed across all of their items so the result covers every variation it sees.
How the types are inferred
- A field that is missing from some objects in an array becomes optional; a field that is
nullin some items becomes nullable. - Whole numbers become integers and any decimal turns the field into a floating-point number.
- Fields with mixed types become unions (or a generic value in languages without unions), and empty arrays become arrays of an unknown type.
- Names come from the JSON keys, with array item types named in the singular (
ordersbecomesOrder).
More languages
Besides the first eight, the language list also offers Rust (serde derive, Option for nullable and optional fields, #[serde(rename)] for keys that are not plain identifiers), Swift (Codable structs with CodingKeys), Dart (classes with fromJson and toJson), Python (Pydantic v2) (BaseModel with Optional and field aliases), PHP (typed classes with fromArray and toArray) and Ruby (classes with from_hash and to_h). Reserved words, keys that are not valid names (spaces, leading digits, non-Latin letters) and type names that clash with the language are renamed, and the original key is kept in the rename, alias or key string. Where a field can hold several types, the output uses the nearest equivalent (for example serde_json::Value, dynamic, Union[...] or mixed) and a comment lists the types seen. The new generators are tested against the real compilers and runtimes that were available when the page was built, but a sample cannot show every case: compile the result in your own project before relying on it.
Several samples
Put a line that contains only --- between JSON samples to merge them into one set of types. A field missing from some samples becomes optional, and a field with different types in different samples becomes a union (or the nearest equivalent with a comment). A single JSON document that is valid on its own is never split. If one sample is invalid, the message names it.
Good to know
A sample can only show what it contains, so review the result and widen types the data does not reveal. The generated code is a starting point: it uses common libraries (System.Text.Json, Jackson, kotlinx.serialization, Zod) and standard naming conventions, and very large numbers are read with 64-bit precision.
Example
For this sample, the TypeScript output marks note as optional because the second item has no such key:
{"orders":[{"sku":"a","qty":1,"note":null},{"sku":"b","qty":2}]}
export interface Order {
sku: string;
qty: number;
note?: null;
}
export interface Root {
orders: Order[];
}The sample shows note only as null, so the tool cannot know it is really a string. Change it to string | null by hand if you know that.
Using the output
- Keys that are not valid identifiers in the target language, such as
user-nameor1st, are renamed (userName,_1st) and keep the original key in the serialization attribute or comment. Names that clash with a language keyword (class,in) get a leading underscore in Python, Java and Kotlin. - Choose the JSON Schema option to validate data rather than type it, then check documents against it with the JSON Schema Validator.
- Whole numbers are typed as 64-bit integers. A value outside that range, or one that loses precision when parsed, needs a string or big-number type chosen by hand.
- An empty object becomes an empty type, and an empty array becomes an array of an unknown type, because the sample holds nothing to infer from.
If the sample comes from an API response, check it with the JSON Validator first, and use the JSON Formatter to read a large payload before pasting it here.
Example
This sample response:
{"id":1,"name":"Ada","email":null,"tags":["a","b"],"address":{"city":"London","zip":"N1"},"scores":[1,2.5],"items":[{"sku":"A","qty":2},{"sku":"B"}]}becomes this TypeScript. Nested objects get their own interface, qty is optional because the second item has no such field, and scores is a list of numbers:
export interface Address {
city: string;
zip: string;
}
export interface Item {
sku: string;
qty?: number;
}
export interface Root {
id: number;
name: string;
email: null;
tags: string[];
address: Address;
scores: number[];
items: Item[];
}The same input as Go structs marks the optional field as a pointer with omitempty, whole numbers as int64 and the mixed list as []float64:
type Item struct {
Sku string `json:"sku"`
Qty *int64 `json:"qty,omitempty"`
}and as Python dataclasses, qty: Optional[int] = None. 14 targets are available: TypeScript (interface or type alias), Zod, Go, Python dataclasses, Python with Pydantic v2, C#, Java (Jackson), Kotlin, Rust (serde), Swift, Dart, PHP, Ruby and JSON Schema.
Why is email typed as null?
The tool can only see the values you paste. In the sample, email is null, so the only type it can infer is null. Paste a response where the field has a real value, or several items so that it can see both cases, and it becomes nullable.
Frequently asked questions
Does the tool look at all items of an array?
Yes. Arrays are analysed across all their items, so a field that is missing from some items becomes optional and one that is null in some becomes nullable.
Can I generate a JSON Schema from my sample?
Yes. Choose JSON Schema as the output, then check data against it with the JSON Schema Validator.
Is my JSON uploaded?
No. The types are inferred in your browser.
Privacy
This tool runs entirely in your browser. What you enter is processed on your device and is not sent to a server.