JSON to Java Class (POJO)
Paste JSON and get Java classes for every nested object, ready to use with a JSON library such as Jackson. Free, no signup, and generated in your browser so your data stays local.
16 lines · processed in your browser, nothing is uploaded
Java output · Root.java
Generated code appears here.Example: JSON to Java
This JSON sample, with the root type named User, produces the Java below using the default options.
{
"id": 1024,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"score": 98.5,
"tags": [
"admin",
"beta"
],
"address": {
"city": "London",
"postcode": "NW1 6XE"
}
}// User.java
package com.example;
import java.util.List;
public class User {
private long id;
private String name;
private String email;
private boolean active;
private double score;
private List<String> tags;
private Address address;
public long getID() { return id; }
public void setID(long value) { this.id = value; }
public String getName() { return name; }
public void setName(String value) { this.name = value; }
public String getEmail() { return email; }
public void setEmail(String value) { this.email = value; }
public boolean getActive() { return active; }
public void setActive(boolean value) { this.active = value; }
public double getScore() { return score; }
public void setScore(double value) { this.score = value; }
public List<String> getTags() { return tags; }
public void setTags(List<String> value) { this.tags = value; }
public Address getAddress() { return address; }
public void setAddress(Address value) { this.address = value; }
}
// Address.java
package com.example;
public class Address {
private String city;
private String postcode;
public String getCity() { return city; }
public void setCity(String value) { this.city = value; }
public String getPostcode() { return postcode; }
public void setPostcode(String value) { this.postcode = value; }
}
How to convert JSON to Java
- 1Paste a JSON object or array into the input.
- 2Select Java as the output language.
- 3Name the root class, for example Customer.
- 4Adjust options such as the package name if needed.
- 5Copy each class into its own .java file.
Getters, setters and Jackson
Jackson maps JSON keys to Java properties through getters and setters or annotated fields. @JsonProperty("original_key") pins the JSON name, so you can follow Java camelCase without breaking deserialization.
Deserialize with new ObjectMapper().readValue(json, Customer.class). If the API may add fields later, configure the mapper or annotate the class with @JsonIgnoreProperties(ignoreUnknown = true) so unknown keys do not throw.
Records and Lombok as alternatives
On Java 16 and later, a record gives you an immutable data class in one line, and recent Jackson versions deserialize records directly. Lombok's @Data or @Value removes getter and setter boilerplate on older codebases.
Whatever style you choose, keep the field types from the generated output: they reflect what was actually in the JSON.
Nulls and boxed types
Primitive fields such as int cannot hold null, so a missing number silently becomes 0. Use boxed types such as Integer or Long for fields that may be absent or null.
JSON numbers without decimals may exceed int range; prefer long for IDs and timestamps.