JSON to Java
ConverterGenerate Java classes from sample JSON with nested types, List generics, getters/setters and JsonProperty annotations for REST API clients and DTO classes.
public class Profile {
@JsonProperty("age")
private int age;
@JsonProperty("city")
private String city;
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getCity() { return city; }
public void setCity(String city) { this.city = city; }
}
public static class RootObject {
@JsonProperty("id")
private int id;
@JsonProperty("name")
private String name;
@JsonProperty("active")
private boolean active;
@JsonProperty("score")
private double score;
@JsonProperty("tags")
private List<String> tags;
@JsonProperty("profile")
private Profile profile;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public boolean getActive() { return active; }
public void setActive(boolean active) { this.active = active; }
public double getScore() { return score; }
public void setScore(double score) { this.score = score; }
public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
public Profile getProfile() { return profile; }
public void setProfile(Profile profile) { this.profile = profile; }
}Related Tools
About JSON to Java
Java is strongly typed, so consuming JSON APIs means writing many POJO/DTO classes by hand - tedious and error-prone. This tool parses your sample JSON locally and generates complete Java classes: field names become camelCase (e.g. user_id becomes userId), nested objects become inner static classes, arrays infer to List<T> generics, numbers map to Integer or Long by range, with optional getters/setters, Jackson @JsonProperty or Gson @SerializedName annotations, and a Lombok @Data option to cut boilerplate. Generated code works out of the box for Spring Boot DTOs, REST clients, and MyBatis/JPA entities. Nothing is uploaded to any server. Note: if your API depends on exact JSON key names (special characters or case-sensitive fields), enable the @JsonProperty annotation so jackson keeps the original mapping during deserialization.
How to Use
- Open the JSON to Java tool
- Select the source and target formats
- Adjust the output options as needed
- Click the Convert button; results appear in real time
- Copy or export the result
Use Cases
- Consume REST APIs — Paste API response JSON and get ready-to-use Java DTOs instantly, skipping manual field mapping.
- Generate ORM entities — Create entity classes from database JSON samples for MyBatis/JPA mapping with consistent types.
- Jackson/Gson modeling — Auto-add @JsonProperty or @SerializedName annotations for both Jackson and Gson frameworks.
- Android/Kotlin interop — Generate Java classes callable from Kotlin with type safety, avoiding hand-written conversions.
- API docs modeling — Generate request/response models from JSON examples in API docs as an integration baseline.
FAQ
Which Java versions are supported?
Generated code is compatible with Java 8+, using standard List<T> generics and annotation syntax, without relying on Java 11+ features.
Can it generate BigDecimal?
Yes. Enable the BigDecimal option and all numeric fields use java.math.BigDecimal, ideal for money and other high-precision fields.
How are nested objects handled?
Each nested object becomes an independent static inner class for clarity and reuse. For very deep nesting, review the structure carefully before generating.
What about fields with underscores?
They are converted to camelCase by default (user_name becomes userName). If your API relies on the original keys, enable @JsonProperty so deserialization maps correctly.
Can it handle array fields?
Yes. Top-level or nested arrays infer to List<T> based on element structure. Empty arrays degrade to List<Object>, so include a sample item with fields for best results.