JSON to Java
Transform JSON payloads into Java POJO classes or modern Java 16+ records with clean typing and List collections.
- Runs in your browser
- Free, no signup
import java.util.List;
public class Root {
public int id;
public String name;
public String email;
public boolean isAdmin; // JSON key: "is_admin"
public List<String> roles;
public Profile profile;
}
public class Profile {
public String bio;
public int reputation;
}
Your files are processed locally in your browser and are not uploaded to our server.
Converting JSON payloads into Java classes is an essential part of enterprise, Android, and Spring Boot development. This tool converts any valid JSON object or array into structured, ready-to-use Java classes and records.
The generator correctly distinguishes between primitive types (int, double, boolean) and boxed object wrappers (Integer, Double, Boolean) when nullability is detected. List collections are automatically typed using java.util.List, and nested objects become separate, cleanly structured classes.
How to use this tool
- Paste your JSON payload into the left editor or click "Load Sample".
- Choose your preferred Java style: traditional POJO classes with public fields or modern Java 16+ records.
- Enter an optional root class name and package declaration if needed.
- Click "Copy Code" to copy the generated Java code or "Download .java" to download the file directly.
Support for Both Classic POJOs and Java 16+ Records
Whether you are maintaining an existing enterprise codebase using traditional Java POJO classes or building modern microservices with Java 16+ immutable records, the generator has you covered.
Select "Java 16+ Record" in the options toolbar to generate concise record components, or choose "POJO Class" for standard field declarations compatible with Jackson, Gson, and Hibernate.
Smart Primitive vs Boxed Wrapper Type Mapping
In Java, primitive types (such as int or double) cannot be null. When an incoming JSON field contains null, the generator automatically uses the boxed object wrapper (Integer or Double) rather than a primitive.
Furthermore, Java collections cannot store primitives, so array fields are typed as List<Integer> or List<String> with the required import java.util.List statement included.
Clean Nested Class Hierarchies
Deeply nested JSON structures are parsed and split into individual, named Java classes. Each class is given a distinct PascalCase identifier derived from the JSON property name, keeping your models organized and easy to maintain.
Safe and Private Browser-Based Execution
Enterprise codebases often handle internal API payloads with strict data privacy guidelines. ToolDuck processes your JSON entirely in your browser with no network transmission.
Frequently asked questions
Can I generate Java 16+ records instead of classes?
Yes. Select "Java 16+ Record" from the class style dropdown to generate modern, immutable record declarations.
Does the output include the necessary Java imports?
Yes. The generator automatically includes "import java.util.List;" whenever list collections are present in your payload.
Are snake_case JSON keys supported?
Yes. Keys like "order_total" or "customer_id" are automatically converted to idiomatic Java camelCase ("orderTotal", "customerId"), and annotated with comments indicating the original JSON key.
Is my JSON uploaded to any backend service?
No. Parsing and Java code generation are executed entirely on your client machine using JavaScript.