About the JSON to Java
Generate Java POJO classes from a JSON sample. Field types are inferred, nested objects become their own classes, and arrays become List<T>.
Key features
- Generates Java POJO classes from a JSON sample
- Infers String, int, long, double, boolean and List<T>
- Nested objects become their own classes
- camelCase field names with @JsonProperty when the JSON key differs
- Optional getters and setters
- Custom root class name
Generate Java classes from JSON
Writing model classes by hand for every API response is slow and error-prone. Paste a JSON sample and this tool generates Java POJOs with typed fields, nested classes, and optional getters and setters, ready to use with Jackson's ObjectMapper or Spring's RestTemplate / WebClient.
Example
{
"id": 1024,
"full_name": "Ada Lovelace",
"active": true,
"address": { "city": "London" },
"roles": ["admin"]
}
generates (getters and setters shortened):
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Root {
private int id;
@JsonProperty("full_name")
private String fullName;
private boolean active;
private Address address;
private List<String> roles;
// getters and setters…
}
public class Address {
private String city;
// getters and setters…
}
Type mapping
| JSON value | Java type |
|---|---|
"text" | String |
42 | int |
9007199254740993 | long |
3.14 | double |
true | boolean |
[...] | List<T> |
{...} | Generated class |
null | Object (refine manually) |
Using the classes
ObjectMapper mapper = new ObjectMapper();
Root root = mapper.readValue(json, Root.class);
In Spring Boot, return or accept the class directly in a @RestController method and Jackson handles the conversion.
Tips for better results
- Use a complete sample. Include every field, and give real values instead of
null. - Arrays of objects. Include at least one element so its class can be generated.
- Dates. JSON dates are strings; change the type to
LocalDate/Instantand register the Jackson JavaTimeModule. - Money. Consider
BigDecimalinstead ofdoublefor prices.
Related tools
Need a schema for gRPC? Use JSON to Protobuf. Working in PHP? Use JSON to PHP Array. To inspect types first, try JSON Deserialize.
How to use the JSON to Java
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The Java appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.