Paste JSON and get Java POJO classes with getters and setters as you type.
Paste JSON, upload a .json file or drop one here.
One file that compiles as is. Copy it or download it as a .java file named after the root class.
Converting…
This free JSON to Java converter reads a JSON sample and writes the Java classes that model it. Paste an API response or a config file and you get a root class for the top-level object, a separate class for every nested object, and private fields with getters and setters. It is a quick way to generate a POJO (plain old Java object) without typing out a dozen fields by hand, and the result is ready to use with Jackson.
Everything runs in your browser. Your JSON is not uploaded, there is no sign-up, and the output updates as you type. Set the root class name and the package, or switch on Lombok if you would rather have a @Data annotation than a wall of accessors.
.json file. You can also drag a file onto the editor..java file named after the root class, such as User.java. Drop it into your project and it compiles.This small user object, converted with the class name User, produces a User class with the nested address as a public static class inside it, all in one file. Notice that first_name became firstName, the timestamp became OffsetDateTime and the price a double.
{
"id": 1,
"first_name": "Ada",
"price": 19.99,
"created_at": "2025-03-14T09:26:53Z",
"address": {
"city": "Oslo"
},
"tags": ["a"]
}package com.example.model;
import java.time.OffsetDateTime;
import java.util.List;
public class User {
private long id;
private String firstName;
private double price;
private OffsetDateTime createdAt;
private Address address;
private List<String> tags;
public long getID() { return id; }
public void setID(long value) { this.id = value; }
public String getFirstName() { return firstName; }
public void setFirstName(String value) { this.firstName = value; }
public double getPrice() { return price; }
public void setPrice(double value) { this.price = value; }
public OffsetDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(OffsetDateTime value) { this.createdAt = value; }
public Address getAddress() { return address; }
public void setAddress(Address value) { this.address = value; }
public List<String> getTags() { return tags; }
public void setTags(List<String> value) { this.tags = value; }
public static class Address {
private String city;
public String getCity() { return city; }
public void setCity(String value) { this.city = value; }
}
}
package com.example.model;
import java.time.OffsetDateTime;
import java.util.List;
@lombok.Data
public class User {
private long id;
private String firstName;
private double price;
private OffsetDateTime createdAt;
private Address address;
private List<String> tags;
@lombok.Data
public static class Address {
private String city;
}
}
| JSON | Java type | Notes |
|---|---|---|
{ } object | A class | Nested objects become static nested classes of the root class, named after the key. |
[ ] | List<T> | T comes from the items. An empty array becomes List<Object>. |
| string | String | Unless it matches one of the three formats below. |
| ISO date-time string | OffsetDateTime | For example 2025-03-14T09:26:53Z. |
| ISO date string | LocalDate | For example 2025-03-16. |
| UUID string | UUID | The java.util.UUID class. |
| whole number | long | Never int. |
| decimal number | double | Also used for whole numbers too big for a long. |
true / false | boolean | The getter is named getPaid(), not isPaid(). |
null | Object | A null is the only sample, so the real type is unknown. |
A sample shows one value, not the range a field can take, so the converter picks the safe type: whole numbers are long and decimals are double. If an array holds both 1 and 2.5, the field becomes List<Double>. Change a long to int by hand when you know the values stay small. For prices, consider BigDecimal instead of double to avoid rounding errors.
A long cannot be null, so if a field is null or absent in some objects of an array, the converter uses the boxed type, such as Long, for it. A field whose only value in your sample is null becomes Object. Replace it with the real type once you know it, or paste a sample where the field has a value.
Field names are written in camelCase, so first-name and first_name both become firstName. Keys that are Java keywords or start with a digit are renamed as well: class becomes rootClass and 1st becomes the1St. The generated code does not carry the original key, so a default Jackson mapper will not find first_name in the JSON. Either set a naming strategy on the mapper, as in the next section, or annotate the field with @JsonProperty, which is the way to handle a key that does not follow a pattern.
// JSON key: "class"
@JsonProperty("class")
private String rootClass;To turn a JSON string into a Java object at runtime, you need a mapper. The classes are plain JavaBeans, so Jackson's ObjectMapper can read and write them with no annotations. Register JavaTimeModule from jackson-datatype-jsr310 for the date types, and use PropertyNamingStrategies.SNAKE_CASE (Jackson 2.12 or newer) when your JSON keys are in snake_case. For a top-level array, pass new TypeReference<List<User>>() {} to readValue. Both readValue and writeValueAsString throw a checked JsonProcessingException.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
ObjectMapper mapper = new ObjectMapper()
.registerModule(new JavaTimeModule()) // OffsetDateTime, LocalDate
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); // first_name -> firstName
User user = mapper.readValue(json, User.class);
String backToJson = mapper.writeValueAsString(user);When two objects have exactly the same keys and types, for example billing and shipping addresses, the converter generates a single class and uses it for both fields. That keeps the output short, but the class name comes from one of the keys. Rename it to something neutral like Address in your editor. For an array at the top level, the converter models one element and names that class with your root class name.
The default output is a mutable POJO: private fields plus a getter and setter for each one, which every Java framework understands. Tick Lombok @Data to leave out the accessors and let Lombok generate them, along with equals, hashCode and toString; the project then needs the Lombok dependency. Since Java 16 you can also use records for immutable data. The converter does not write records, but the conversion is mechanical: the fields become the record components, and Jackson 2.12 and later reads and writes records.
public record User(long id, String firstName, double price,
OffsetDateTime createdAt, Address address, List<String> tags) {
public record Address(String city) {}
}Java allows only one public top-level class per file, and the file must be named after it. So the root class is the only top-level class in the output, and every other class, along with any enum the converter generates for a field with a few repeated string values, is nested inside it as a public static member. The package line and the imports sit once at the top. Save the output as User.java (the Download button already uses the root class name) and it compiles with no editing.
In other code, refer to a nested class through the root, as User.Address, or import it with import com.example.model.User.Address;. Jackson reads static nested classes the same way as top-level ones. If you prefer one file per class, move a nested class out, drop the static keyword and give it its own file. If the root class name clashes with a java.lang type such as String, the converter renames it, for example to PurpleString, and the download follows the new name.
Need example data to try this with? Create it with the JSON Generator. To describe the same data as a contract, use the JSON Schema Generator, and if you also work in other languages, there are converters for JSON to TypeScript, JSON to C# classes and JSON to Go structs. When a typed schema matters more than the text format, our comparison of Protobuf vs JSON is worth a read.
Paste your JSON into the JSON Input editor, or upload a .json file. The Java classes appear in the output editor as you type. Set the root class name and package, then copy the code or download it. The download is a single .java file named after the root class, such as User.java, and it compiles as it is.
Yes. The root class is the only top-level public class, and every other class is a public static nested class inside it, so the whole output compiles as one file named after the root class. Refer to a nested class as User.Address, or import it.
A POJO (plain old Java object) is an ordinary class with private fields and getters and setters, with no framework base class. This converter generates exactly that from a JSON sample: one class for the root object and one for every nested object.
Whole numbers become long, never int, because a sample cannot tell you how large a value may get. Numbers with a decimal part become double. A field that is null or missing in some objects of an array becomes the boxed type, such as Long.
Strings in ISO 8601 date-time form, such as 2025-03-14T09:26:53Z, become OffsetDateTime, and plain dates such as 2025-03-16 become LocalDate. UUID strings become java.util.UUID. Any other format stays a String. With Jackson, add the jackson-datatype-jsr310 module to read the java.time types.
Field names are converted to camelCase, so order_id becomes orderID and keys that are Java keywords or start with a digit get a safe name. The original key is not kept in the output. Set Jackson's SNAKE_CASE naming strategy to map snake_case keys back, or add @JsonProperty to individual fields.
Tick Lombok @Data to replace the getters and setters with a single @lombok.Data annotation on each class. The tool does not generate records, but a generated class is easy to turn into one: use the field names and types as the record components.
No. The classes are generated entirely in your browser with JavaScript, so your JSON never leaves your device. That makes it safe to use with real API responses and internal data.