JSON to Class Generator

Paste a JSON sample, pick a language and get ready-to-use classes. Nested objects become separate classes. You can also paste Java toString() output, such as a Lombok DTO from your logs, and get it back as JSON.

Input Code
Ready - Type or paste code in the left panel
Output Code
Ready - Type or paste code in the left panel

How to generate classes from JSON

  1. Paste a JSON object into the left panel, or click Load Sample.
  2. Pick the output language on the right: Java, TypeScript, Python, JavaScript, C#, Go, Kotlin, Rust, Pydantic or Zod.
  3. For Java, choose Lombok or a plain POJO and which constructors you want.
  4. 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:

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

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"] }

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.

Share Content

Choose what to share and generate an instant link

🔥 One-time link Content deleted from server after first view
✉️
Uploading to server…