JSON to Java Class (POJO)
Generate a compilable Java class from sample JSON; nested objects become their own classes, missing fields get wrapper types
Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.
Did this tool do the job?
Thanks, your feedback came through.
How it works
To read a REST API response as objects in Java, you first need classes that match the JSON, and writing them by hand gets long and error-prone as fields pile up. Paste a sample response into the left pane and type a root class name (for example Order); the Java code appears on the right. Every nested object becomes its own class, written inside the root class as a public static class, so the output compiles as a single Order.java file. An array of objects becomes List<...>, and the element class is named after the singular of the array: "items" → Item, "categories" → Category. All entries of an array are merged into one type: a field missing from one entry is still in the class, but written with a wrapper type such as Integer, Double or Boolean so it can hold null. Whole numbers become int, whole numbers beyond about 2 billion become long, and decimals become double; the type is read from how the number is written in the JSON, so 59.0 stays double. A key like "customer_name" becomes a customerName field, and @JsonProperty("customer_name") is added so Jackson can map it. Choose record to get short, immutable types for Java 16 and later.
This tool is also known as json to java, json to pojo, json to java class, json to java converter, json to java record.
What is POJO?
A POJO (Plain Old Java Object) is a simple Java class tied to no framework: private fields, a no-argument constructor and getter/setter methods for the fields. Jackson, Gson and Spring expect exactly this shape when turning JSON into Java objects, matching field names to JSON keys. That is why the first step in calling an API from Java is usually writing POJOs for its responses.
What is Java record?
A record is a compact class form introduced in Java 16 for carrying data: the line record Item(String product, int qty) {} generates the fields, the constructor, the accessors, equals and hashCode automatically. Records are immutable; their fields cannot change after construction. Jackson reads records directly since version 2.12. They suit API responses you read and display; choose a class if you need to modify the object afterwards.
What is the difference between a POJO and a record in Java?
A POJO is the classic class with a separate getter and setter for each field: long, but it runs on every Java version and the object can be changed after reading. A record defines the same data in one line, and the compiler generates accessors, equals, hashCode and toString; it needs Java 16 or later and is immutable. Jackson reads both (records from 2.12). For code that reads and shows an API response, a record does the job in fewer lines; if you edit the object and send it back, or you are on an older Java, use a POJO.
How the types are inferred: merging, wrapper types, naming
The tool infers from one sample, so the more variation your sample shows, the more accurate the class. Entries of an array are merged into one type: if the first item has a discount and the second does not, discount is still in the class, but as Double instead of double, because Jackson sets a missing field to null and a primitive double cannot hold null. A field seen as null also gets a wrapper type; a field that is only ever null has no known type and becomes Object.
If a field shows different types (a number in one entry, text in another), the common type is Object; an empty array becomes List<Object>. Java reserved words such as class or default cannot be field names, so they get a trailing underscore and the original name is kept with @JsonProperty. If a class name made from a key clashes with a Java type such as String or List, a 2 is appended.
- [{"a":1},{"b":2}] → Integer a; Integer b; (each missing in one record)
- {"note": null} → Object note (type unknown)
- {"total": 59.0} → double (the .0 in the JSON is read)
- {"customer_name": "x"} → @JsonProperty("customer_name") String customerName
Class or record, and honest limits
The class style works on every Java version and with the default settings of Jackson, Gson and Spring: private fields plus a getter and a setter for each; a boolean's getter is named isX. The record style exists since Java 16: fields are constructor parameters, the type is immutable, and Jackson 2.12 and later reads it directly. Pick the class style if your team is on an older Java or if you change the object after reading it.
Honest limits: date strings (2026-09-27) are not turned into LocalDate and fixed value sets are not turned into enums; they stay String. Odd JSON names (with spaces or emoji) are adapted for Java, while @JsonProperty carries the original. If you do not use Jackson, remove the import and the annotations or swap them for your library's equivalent (@SerializedName in Gson).
Frequently asked questions
How do I create a Java class from JSON?
Paste sample JSON into the left pane on this page and type the root class name. The right pane shows a Java class with nested objects as static inner classes and getters and setters in place. Copy the code and save it in your project as a file named after the root class (for example Order.java).
Why are some fields Integer instead of int?
That field is missing from some entries of an array, or it was null in the JSON. Jackson sets a missing or null field to null, and a primitive int cannot hold null, so the field is written as Integer. If you are sure every field is always present, set Missing or null fields to Required and int is used instead.
Why was a @JsonProperty annotation added?
When a JSON key does not follow Java naming (customer_name, first-name), the field name is converted to camelCase: customerName. So that Jackson can still match this field to the right key when reading JSON, the original name is written as @JsonProperty("customer_name"). Keys that are already camelCase get no annotation.
Is the JSON I paste sent to a server?
No. Type inference and writing the Java code happen entirely in your browser, so even a sample response with customer data or API keys never leaves this page. Once loaded, the page also works offline.