How to generate classes from JSON
- Paste a JSON object into the left panel, or click Load Sample.
- Pick the output language on the right: Java, TypeScript, Python, JavaScript, C#, Go, Kotlin, Rust, Pydantic or Zod.
- For Java, choose Lombok or a plain POJO and which constructors you want.
- Click Convert, then Copy Output.
What you get
Every JSON object becomes a class, and nested objects get a class of their own, named after their key. The top-level class is called RootObject, so rename it to fit your code. In Java, C# and TypeScript, field types come from the sample values: text becomes String, whole numbers become int, decimals become double, and so on. For example, with Java and Lombok:
{ "userName": "ada", "age": 36, "address": { "city": "London" } } produces an Address class with a city field, and a RootObject class with userName, age and address, each annotated with @Data and the constructor annotations you picked.
Guides for each language
Each language has its own page with an example, how JSON types map, and tips for using the result: JSON to Java · JSON to TypeScript · JSON to Python · JSON to Go · JSON to C# · JSON to Kotlin.
Go, Kotlin, Rust, Pydantic and Zod
These are built from the JSON sample right in your browser, following each language's usual style:
- Go: exported struct fields with
json:"key"tags; optional fields become pointers withomitempty. - Kotlin:
@Serializabledata classes; keys that aren't valid camelCase names get@SerialName. - Rust:
serdestructs with snake_case fields,#[serde(rename)]where needed andOption<T>for optional values. - Pydantic: v2
BaseModelclasses with snake_case fields andField(alias=...)for the original keys. - Zod: one schema per object plus a TypeScript type from
z.infer.
If you paste an array of objects, fields missing from some items are marked optional and fields that are sometimes null become nullable.
Tips for better results
- Use a sample where every field has a real value. A field that is
nullin the sample can't tell the generator its type. - If a number can have decimals, put a decimal value like
9.5in the sample so it isn't typed as a whole number. - Check list fields after generating. Arrays may come out as a generic
Objecttype that you'll want to change to a typed list. - Choose Snake Case output for Python if your API uses
user_namestyle keys.
Convert Java toString() output to JSON
Logs and debuggers show Java objects the way toString() prints them, which isn't JSON:
UserDTO(id=1, name=Amit, address=AddressDTO(city=Gurugram, pincode=122001), skills=[Java, Spring Boot])
Choose Java toString() / DTO as the input language, paste the text and click Convert. You get proper JSON that you can put into Postman, a test fixture or a mock server:
{ "id": 1, "name": "Amit", "address": { "city": "Gurugram", "pincode": 122001 }, "skills": ["Java", "Spring Boot"] } - Works with Lombok
@ToString,@Dataand@Value, Kotlin data classes, and Java records (User[id=1, name=Amit]). - Nested objects, lists, sets, maps (
{key=value}),Optionalandnullare converted. Numbers andtrue/falsebecome JSON numbers and booleans; everything else becomes a string. Values with leading zeros, such as007, stay text, and long IDs keep every digit. - Text containing commas or brackets, like
address=Flat 4, MG Road, is kept together. - You can paste a whole log line; the text before the object is skipped. Paste several lines and you get a JSON array.
- Tick Add @type to keep each object's class name, and pick Snake Case to rename
roleNametorole_name. - Pick any other output language to go one step further and generate classes from the same text.
Because toString() doesn't quote strings, a value that happens to look like a number, such as a PIN code, becomes a JSON number. Quote it in the result if your API expects text.
Is my code sent anywhere?
Converting toString() output to JSON, and generating Go, Kotlin, Rust, Pydantic and Zod, happen in your browser. The other class generators run on our server: your input is sent, converted in memory and returned. It isn't stored. See the privacy policy for details.
Frequently asked questions
Which languages can I generate?
Java (with Lombok annotations or as a plain POJO), TypeScript, Python, JavaScript and C#, plus Go structs with json tags, Kotlin data classes for kotlinx.serialization, Rust structs for serde, Pydantic v2 models and Zod schemas. The last five are generated in your browser and keep the original JSON key names through tags, aliases or renames.
Why is my top-level class called RootObject?
JSON doesn't name its outermost object, so the generator uses RootObject. Rename it after copying the code.
How are field types chosen?
In Java, C# and TypeScript the types come from the values in your sample: text becomes a string, whole numbers an integer, decimals a double or number, and true/false a boolean. Python and JavaScript classes are generated without type annotations. A field that is null in the sample has no type to go on, so give it a real value before converting.
How do I convert a Lombok toString() to JSON?
Set the input language to Java toString() / DTO, paste the output (for example UserDTO(id=1, name=Amit, skills=[Java])) and click Convert with JSON as the output. Nested DTOs, lists, maps and Java records are supported, and it runs in your browser.
Does it handle nested objects?
Yes. Every nested object becomes its own class, named after its key, and the parent class gets a field of that type.