Output will appear here
Output will appear here
Paste JSON and this tool writes Java POJOs for Jackson: private fields, a getter and setter for each, and @JsonProperty("key") on every field so the original JSON key is kept. Types are boxed (Integer, Double, Boolean) so a null or missing value never breaks a primitive. All classes fit in one file, Root.java.
By Ankit Aglawe · Updated · Runs entirely in your browser
Keys with a leading underscore like _source become plain source fields, and @JsonProperty("_source") maps them back. The outer hits object becomes Hits and the array inside it becomes List<Hit>. Only Root is public; the others are package-private so the file compiles as Root.java.
{
"took": 12,
"timed_out": false,
"hits": {
"total": { "value": 2, "relation": "eq" },
"max_score": 1.38,
"hits": [
{ "_index": "products", "_id": "sku-1001", "_score": 1.38, "_source": { "name": "Trail Shoe", "price": 89.95, "in_stock": true } },
{ "_index": "products", "_id": "sku-1002", "_score": 0.92, "_source": { "name": "Rain Jacket", "price": 120.0, "in_stock": false } }
]
}
}// Save as Root.java
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
class Total {
@JsonProperty("value")
private Integer value;
@JsonProperty("relation")
private String relation;
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
}
class Source {
@JsonProperty("name")
private String name;
@JsonProperty("price")
private Double price;
@JsonProperty("in_stock")
private Boolean inStock;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Boolean getInStock() {
return inStock;
}
public void setInStock(Boolean inStock) {
this.inStock = inStock;
}
}
class Hit {
@JsonProperty("_index")
private String index;
@JsonProperty("_id")
private String id;
@JsonProperty("_score")
private Double score;
@JsonProperty("_source")
private Source source;
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
public Source getSource() {
return source;
}
public void setSource(Source source) {
this.source = source;
}
}
class Hits {
@JsonProperty("total")
private Total total;
@JsonProperty("max_score")
private Double maxScore;
@JsonProperty("hits")
private List<Hit> hits;
public Total getTotal() {
return total;
}
public void setTotal(Total total) {
this.total = total;
}
public Double getMaxScore() {
return maxScore;
}
public void setMaxScore(Double maxScore) {
this.maxScore = maxScore;
}
public List<Hit> getHits() {
return hits;
}
public void setHits(List<Hit> hits) {
this.hits = hits;
}
}
public class Root {
@JsonProperty("took")
private Integer took;
@JsonProperty("timed_out")
private Boolean timedOut;
@JsonProperty("hits")
private Hits hits;
public Integer getTook() {
return took;
}
public void setTook(Integer took) {
this.took = took;
}
public Boolean getTimedOut() {
return timedOut;
}
public void setTimedOut(Boolean timedOut) {
this.timedOut = timedOut;
}
public Hits getHits() {
return hits;
}
public void setHits(Hits hits) {
this.hits = hits;
}
}public is a Java keyword, so the field is public_ with getPublic_(), and @JsonProperty("public") keeps the wire name. discountCode appears in only one line item but still gets a field: Jackson leaves it null when the key is absent. unitPrice is Double because one sample has a fraction.
{
"orderId": "ORD-2024-0091",
"customerId": 48213,
"status": "PAID",
"public": true,
"lineItems": [
{ "productCode": "BK-114", "quantity": 2, "unitPrice": 14.5 },
{ "productCode": "BK-207", "quantity": 1, "unitPrice": 32.0, "discountCode": "FALL10" }
],
"shippingAddress": { "line1": "12 Harbour St", "city": "Leeds", "postcode": "LS1 4AB" }
}// Save as Root.java
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
class LineItem {
@JsonProperty("productCode")
private String productCode;
@JsonProperty("quantity")
private Integer quantity;
@JsonProperty("unitPrice")
private Double unitPrice;
@JsonProperty("discountCode")
private String discountCode;
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public Double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Double unitPrice) {
this.unitPrice = unitPrice;
}
public String getDiscountCode() {
return discountCode;
}
public void setDiscountCode(String discountCode) {
this.discountCode = discountCode;
}
}
class ShippingAddress {
@JsonProperty("line1")
private String line1;
@JsonProperty("city")
private String city;
@JsonProperty("postcode")
private String postcode;
public String getLine1() {
return line1;
}
public void setLine1(String line1) {
this.line1 = line1;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
}
public class Root {
@JsonProperty("orderId")
private String orderId;
@JsonProperty("customerId")
private Integer customerId;
@JsonProperty("status")
private String status;
@JsonProperty("public")
private Boolean public_;
@JsonProperty("lineItems")
private List<LineItem> lineItems;
@JsonProperty("shippingAddress")
private ShippingAddress shippingAddress;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Boolean getPublic_() {
return public_;
}
public void setPublic_(Boolean public_) {
this.public_ = public_;
}
public List<LineItem> getLineItems() {
return lineItems;
}
public void setLineItems(List<LineItem> lineItems) {
this.lineItems = lineItems;
}
public ShippingAddress getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(ShippingAddress shippingAddress) {
this.shippingAddress = shippingAddress;
}
}Every code generator on this site is run on the same awkward input: a 64-bit id, a float written as 1.0, a null, a date string, a reserved word as a key, an empty array, a nested array and an array of objects whose keys differ. This is the exact output for Java, generated when the page was built.
{
"id": 9007199254740993,
"price": 19.99,
"ratio": 1.0,
"deleted_at": null,
"created_at": "2024-01-15T10:30:00Z",
"class": "premium",
"tags": [],
"matrix": [[1, 2], [3, 4.5]],
"items": [{ "sku": "A1", "qty": 1 }, { "sku": "B2", "qty": 2, "note": "gift" }]
}// Save as Root.java
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
class Item {
@JsonProperty("sku")
private String sku;
@JsonProperty("qty")
private Integer qty;
@JsonProperty("note")
private String note;
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public Integer getQty() {
return qty;
}
public void setQty(Integer qty) {
this.qty = qty;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
public class Root {
@JsonProperty("id")
private Long id;
@JsonProperty("price")
private Double price;
@JsonProperty("ratio")
private Integer ratio;
@JsonProperty("deleted_at")
private Object deletedAt;
@JsonProperty("created_at")
private String createdAt;
@JsonProperty("class")
private String class_;
@JsonProperty("tags")
private List<Object> tags;
@JsonProperty("matrix")
private List<List<Double>> matrix;
@JsonProperty("items")
private List<Item> items;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getRatio() {
return ratio;
}
public void setRatio(Integer ratio) {
this.ratio = ratio;
}
public Object getDeletedAt() {
return deletedAt;
}
public void setDeletedAt(Object deletedAt) {
this.deletedAt = deletedAt;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getClass_() {
return class_;
}
public void setClass_(String class_) {
this.class_ = class_;
}
public List<Object> getTags() {
return tags;
}
public void setTags(List<Object> tags) {
this.tags = tags;
}
public List<List<Double>> getMatrix() {
return matrix;
}
public void setMatrix(List<List<Double>> matrix) {
this.matrix = matrix;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}Java has no optional-field syntax for POJOs, so every field is a boxed type that can hold null. A key that is null in the JSON and a key that is missing both leave the field null. note in the edge-case output gets an ordinary String field even though one item lacks it.
With no typed sample, deleted_at becomes Object deletedAt. Jackson will put whatever it finds there (a String, a Map, a List). Replace Object with the real type when you know it.
A whole-number field becomes Integer while every value seen fits in 32 bits, and Long as soon as one value is above 2,147,483,647, which is why id is Long in the edge-case output. If your sample only has small ids but production ids or millisecond timestamps can grow, change the field to Long by hand. Also note 1.0 reaches the converter as 1, so ratio comes out Integer, and Jackson by default truncates a later 1.5 to 1 instead of failing. Use Double for anything that can hold a fraction.
Java has no escape syntax for identifiers, so a reserved word gets a trailing underscore: class becomes class_ with getClass_() and setClass_(). A plain getClass() would clash with the final method on Object. @JsonProperty("class") keeps the JSON key.
Timestamps stay String. To get Instant or OffsetDateTime, change the field type by hand and register JavaTimeModule (from jackson-datatype-jsr310) on your ObjectMapper.
[[1, 2], [3, 4.5]] becomes List<List<Double>> because all inner values are merged. An empty array becomes List<Object>, since there is no element to infer from.
| JSON value | Java type | Notes |
|---|---|---|
| string | String | Dates stay String too |
| integer | Integer or Long | Long when a value exceeds 2^31 - 1 |
| number with a fraction | Double | |
| true / false | Boolean | |
| null or missing key | same boxed type, value null | |
| only ever null | Object | |
| object | class Name | Named after its key, PascalCase |
| array | List<T> | Imports java.util.List |
| mixed types or empty array | Object / List<Object> |
Enter a JSON object or array into the input editor. The converter handles nested objects, arrays of mixed types, and deeply structured API responses.
The output pane displays Java POJO classes with private fields, getters, setters, and Jackson annotations like @JsonProperty for each key. Nested objects produce separate inner or top-level classes.
Copy the generated classes or download them as .java files. Drop them into your Maven or Gradle project and deserialize JSON with ObjectMapper immediately.
Paste the JSON on the left, copy the output into Root.java, and add the jackson-databind dependency. Then read it with new ObjectMapper().readValue(json, Root.class).
Yes. Each JSON object becomes a plain class with private fields, a public getter and setter per field, and the implicit no-argument constructor Jackson needs. There are no records, builders or Lombok annotations.
Field names are converted to camelCase and keywords get an underscore, so the Java name often differs from the JSON key. The annotation pins the exact key, which keeps Jackson from guessing the name from the getter.
Gson ignores @JsonProperty. Keys that are already camelCase still match, but snake_case keys like timed_out will not map unless you add Gson's @SerializedName or set a field naming policy.
Jackson's FAIL_ON_UNKNOWN_PROPERTIES is on by default. Add @JsonIgnoreProperties(ignoreUnknown = true) to the classes or disable that feature on your ObjectMapper.
Java allows one public top-level class per file. Root is public and the rest are package-private, so the whole output compiles as Root.java. Move them into their own files and make them public if other packages need them.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.