JSON to Java Class Generator
Paste a JSON response and get the Java classes to deserialize it into: typed fields, nested classes, lists, and @JsonProperty where a key is not a valid Java name.
Runs entirely in your browser — nothing you enter here is sent to a server.
From a JSON sample to Java classes
Calling a JSON API from Java means writing a class for every object in the response — a field for each key, the right type for each value, another class for every nested object. It is mechanical work with plenty of room for typos, and the generator does it from a single example.
Types from values
Strings become String, whole numbers int (or long beyond the 32-bit range), decimals double, booleans boolean, and null becomes Object for you to refine.
Nested objects and arrays
Each nested object becomes its own class, named after its key. Arrays become List<T>; for arrays of objects the fields of all elements are merged.
Naming
order_number becomes the field orderNumber with @JsonProperty("order_number"), so Jackson still maps it correctly.
Three styles
Lombok @Data for the least code, classic getters and setters with no dependencies, or public fields for quick scripts and tests.
Reviewing the result
A sample shows what one response looked like, not what the API guarantees. Check three things before you rely on the classes. A field that was null in the sample has no known type. A field present only in some array elements is optional, and is given a boxed type (Boolean, Integer) so it can be absent. And dates arrive as strings — change them to Instant or OffsetDateTime and register Jackson's Java time module.
Put each public class in its own file, or make the nested ones static inner classes. For money, replace double with BigDecimal: binary floating point cannot represent values such as 0.1 exactly.
Frequently asked questions
What is a POJO?
A Plain Old Java Object: a simple class with fields and accessors, used to hold data. JSON libraries such as Jackson and Gson fill POJOs from JSON and write them back.
How do I use the generated classes with Jackson?
Root value = new ObjectMapper().readValue(json, Root.class); The @JsonProperty annotations map JSON keys that differ from the Java field names.
Why are some fields Integer or Boolean instead of int or boolean?
Those fields were missing from some elements of an array in the sample, so they may be absent. A boxed type can be null; a primitive cannot.
Does it generate Java records?
Not at present. The fields map directly onto record components, so converting a generated class to a record is a small edit.