JSON to Java Classes (POJO or Record)
Create Java POJOs with getters and setters or Java 16 records from JSON, using Jackson @JsonProperty for unusual keys and nested static classes. Free.
Nested types are static nested classes. Keys that are not valid Java names get @JsonProperty (Jackson).
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is JSON to Java Class?
Generate Java model classes from a JSON sample, either as classic POJOs with private fields, getters and setters or as compact Java records. Nested objects become static nested classes (or nested records) inside the root type.
How to use JSON to Java Class
- Paste a JSON sample into JSON input (or click Load sample / Open file).
- Set the Root type name (default
Root). - Choose Output style: Class with getters/setters (Jackson) or Record (Java 16+).
- Copy the generated Java code or Download it as a file.
Example
{"id":1,"name":"A","tags":["x"]} import java.util.List;
public class Root {
private long id;
private String name;
private List<String> tags;
public long getId() { return id; }
public void setId(long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
} When to use JSON to Java Class
Use it to scaffold DTOs for Spring, Jackson or Gson code. Adjust types such as dates (LocalDate, Instant) and enums by hand, and split nested classes into files if your codebase prefers that.
How JSON to Java Class works
The sample is walked recursively and every position collects the types it has seen. Arrays of objects are merged into one type: a key missing from some elements becomes optional, a key that is null somewhere becomes nullable, integers mixed with decimals become a floating-point type, and anything else that mixes types falls back to a dynamic type. Nested objects become their own named types (PascalCase of the key, array keys singularized: orders → Order), with numeric suffixes when names collide. Java output uses long/double/boolean primitives for required values and boxed Long/Double/Boolean for nullable or optional ones, String, List<T> for arrays and Object for dynamic values. Field names are camelCase; when they differ from the JSON key a Jackson @JsonProperty("key") annotation is added and the import is included automatically.
Common Use Cases
- Create DTOs for a Spring Boot REST client
- Model a JSON message for Kafka consumers
- Generate records for immutable configuration
- Bootstrap test fixtures in Java
FAQs
Do I need Jackson?
Only if some keys are not valid Java names; then @JsonProperty is used. Otherwise the classes are plain Java and work with Gson too.
Why long instead of int?
JSON numbers can exceed the int range (IDs, timestamps). long avoids overflow; switch to int if you know values are small.
Do records work with Jackson?
Yes, Jackson 2.12+ deserializes Java records via their canonical constructor.