Paste a JSON object or API response and get ready-to-use Java model classes: camelCase fields, the right Integer, Long, Double, Boolean and List types, nested classes for nested objects, and optional Lombok, records, Jackson or Gson annotations. Conversion runs entirely in your browser.
Last updated:
Your JSON is parsed locally in this tab and never uploaded. Tip: Ctrl + Enter generates.
Advertisement
Advertisement
How to use the JSON to Java Class
Paste your JSON into the left box or open a .json file. A sample is loaded so you see output right away.
Name the root class and set a package, or clear the package to leave it out.
Choose a code style: getters and setters, Lombok, records or public fields, and pick Jackson, Gson or no annotations.
Choose how nested objects are written: static inner classes in one file, or one file per class.
Copy or download the code and deserialize with new ObjectMapper().readValue(json, Root.class).
Example: JSON to a Java POJO
For {"id": 7, "user_name": "ada", "price": 9.99, "tags": ["new"]} with getters/setters and Jackson, the tool produces:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Root {
@JsonProperty("id")
private Integer id;
@JsonProperty("user_name")
private String userName;
@JsonProperty("price")
private Double price;
@JsonProperty("tags")
private List<String> tags;
public Integer getId() {
return id;
}
// … more getters and setters
}
Read it with Jackson: Root root = new ObjectMapper().readValue(json, Root.class); or with Gson: Root root = new Gson().fromJson(json, Root.class);. For a top-level array use new TypeReference<List<Root>>() {}.
JSON to Java type mapping
JSON value
Java type
With "Primitive types"
"text"
String
String
42
Integer
int
3200000000 (beyond ±2,147,483,647)
Long
long
9.99, 1e3
Double
double
true / false
Boolean
boolean (getter isX())
[ … ]
List<T>
List<T>
{ … }
A new class
A new class
{}
Map<String, Object>
Map<String, Object>
null, mixed types
Object
Object
Fields that are null or missing in some array items always keep the wrapper type, because a primitive cannot hold null. For money values, consider changing Double to BigDecimal after generating.
Dependencies for the annotations
Library
Maven coordinates
Jackson
com.fasterxml.jackson.core:jackson-databind (included in Spring Boot)
Paste the JSON into the input box. The tool reads every key and value, creates one class for each distinct object shape, maps values to Java types and writes fields, getters and setters (or Lombok annotations or a record). Then copy the code into your project or download the .java file.
Which Java types are used?
Strings become String, whole numbers Integer (or Long when a value does not fit in 32 bits), numbers with a decimal point or exponent Double, true/false Boolean, arrays List<T>, nested objects their own class, and empty objects Map<String, Object>. Values that are always null, empty arrays and mixed types become Object. Tick Primitive types to use int, long, double and boolean for fields that are never null or missing.
Jackson or Gson annotations?
Use Jackson (@JsonProperty) for Spring Boot and most Java backends, because Jackson is Spring's default JSON library. Use Gson (@SerializedName) for Android or projects that already use Gson. The annotation maps each camelCase field back to the exact JSON key, so keys such as avatar_url or email-notifications still deserialize correctly.
What do the Lombok annotations do?
@Data generates getters, setters, equals, hashCode and toString; @Builder adds a fluent builder; @NoArgsConstructor and @AllArgsConstructor add the constructors that Jackson and the builder need. Add the org.projectlombok:lombok dependency and enable annotation processing in your IDE.
Can I generate Java records?
Yes. Choose Records (Java 16+) to get immutable record classes with the JSON annotations on each component. Jackson 2.12 and later and Gson 2.10 and later can deserialize records directly.
How are arrays of objects handled?
All objects in an array are merged into one class. A key that appears in only some items is still included, so no data is lost; with Primitive types ticked such a field stays a wrapper type (for example Integer) so it can hold null.
Is my JSON uploaded?
No. Parsing and code generation run in JavaScript inside this page, so your JSON never leaves your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.