CraftTools

JSON to DTO Generator

Guide: Turn JSON or XML Into Classes (DTOs) in Java, C# and More

3 classes

Nothing you enter or choose here leaves your device. This tool runs in your browser.

From a sample to typed code

A data transfer object is a plain class that holds the fields of an API request or response. Writing one by hand from a long JSON reply is slow and easy to get wrong, so you paste a sample and the tool writes the class. Here's a small order:

{"id": 7, "name": "Ada", "price": 9.5, "tags": ["a", "b"],
 "address": {"city": "Leeds", "zip": null}}

In TypeScript, with a root name of Order, you get:

export interface Order {
  id: number;
  name: string;
  price: number;
  tags: string[];
  address: Address;
}

export interface Address {
  city: string;
  zip: unknown;
}

The same sample in Python becomes two dataclasses, with zip as an optional field, and in Java it becomes two classes with private fields and getters and setters. Every nested object gets its own class, lists become list types, and the root name is whatever you chose.

How types are guessed

In the sampleJavaTypeScriptPython
7Integernumberint
9.5Doublenumberfloat
"Ada"Stringstringstr
["a","b"]List of Stringstring[]List[str]
nullObjectunknownOptional[Any]
A nested objectIts own classIts own interfaceIts own dataclass

Make the sample count

The tool only knows what it sees, so the sample decides the quality of the result.

  • Include a fractional value. JSON can't tell 10 from 10.0, so a price that's always whole in your sample becomes an integer. Put 10.5 in one record, or change the type by hand.
  • Send a list with several items. Fields missing from some of them are marked optional, and fields that are null are marked nullable.
  • Replace nulls with real examples where you can. A null tells the tool nothing about the type.
  • Use real, varied data. One record with every field filled in, plus one with gaps, gives the most accurate result.

The options

  • Language: Java, C#, TypeScript, Kotlin, Python or Go.
  • Style: for Java a plain class, Lombok or a record. For C# a class or a record. For TypeScript an interface, a type or a class.
  • Annotations: adds serializer hints such as Jackson in Java or JSON tags in Go, so field names that differ from your code style still map correctly.
  • Package or namespace: put the right line at the top of the output.

In Java and C#, each class normally lives in its own file. The output puts them together so you can copy it in one go, with a comment reminding you to split them.

A good way to finish

  1. Generate the classes and paste them into your project.
  2. Rename fields where the API's names are awkward, and add the matching annotation.
  3. Check the numbers: change any integer that should be a decimal, or a long where ids get big.
  4. Parse a real response with the new classes to confirm nothing is missing.

Your JSON stays in your browser, so private API replies are safe to paste. To tidy the sample first, use the JSON formatter. To describe the same data as a schema, use the JSON schema generator, and for XML input, the XML to DTO tool. The guide to JSON, classes and DTOs goes deeper.

Written by Akinrinmade Michael · Updated October 24, 2026

How to use

  1. 1Paste a JSON object, or a list of objects, into the input box.
  2. 2Choose the language and, if you like, a root class name and package.
  3. 3Pick a style and turn annotations on or off.
  4. 4Click Copy code and paste it into your project.

Frequently asked questions

What is a DTO?

A data transfer object is a simple class that holds the fields of a request or response, such as an API result, so you can use it as typed data in your code.

How are types and nested objects handled?

Every nested object becomes its own class, lists become List or array types, and numbers become int, long or double depending on the values. Fields that are missing from some objects in a list are marked optional, and fields that are null become nullable.

Why does 10.0 become an integer?

JSON doesn't tell integers and decimals apart, and 10.0 is read as the number 10. If a field can be fractional, include a value like 10.5 in your sample, or change the type by hand.

Is my JSON uploaded anywhere?

No. The classes are generated in your browser, so private API responses stay on your device.

Read the guide

Learn how this works and how to get the most from it.

Developer

Turn JSON or XML Into Classes (DTOs) in Java, C# and More

What a DTO is, how generated classes map JSON and XML, and the details to check before you trust a generated model.

3 min read

XML to DTO Generator

Turn XML into Java (JAXB), C#, TypeScript, Kotlin, Python or Go classes.

JSON Formatter & Validator

Prettify, minify and validate JSON, with error line numbers.

Text Diff Checker

Compare two texts side by side and see exactly what changed.

Base64 & URL Encoder / Decoder

Encode and decode Base64 and URL-encoded text instantly.