Skip to content
100% local

JSON to Java class

Turn a JSON sample into Java classes, with nested types and generic lists inferred automatically.

Input
Output

JSON to Java class

Paste a JSON sample and this tool generates the Java classes needed to represent it, inferring field types, nested object types and generic list element types directly from the values you provide. It is built for backend developers who receive an API response or a config file and need a typed model to deserialize it into, without hand-writing every field.

Choose how fields are annotated: none, Jackson's @JsonProperty, or Gson's @SerializedName, each carrying the original JSON key so serialization still matches after a field is renamed to camelCase. Turn off getters and setters for a plain class with public fields, or replace them with Lombok's @Data or a Java record, where components take the place of fields and accessors. Wrapper types (Integer, Boolean, Double) can be forced everywhere instead of primitives; the tool always uses a wrapper where a value is genuinely optional, since a primitive can never hold null. A package declaration is added when supplied, and nested objects render as static nested classes in one file or as separate top-level classes.

When the same shape appears more than once — repeated objects in an array, or two sibling fields with identical structure — the tool reuses a single generated class instead of duplicating it. Fields observed with different shapes across an array are merged into one class, with fields absent from some elements marked optional. Numbers stay as int where they fit a 32-bit range and widen to long or double as needed; a JSON key that cannot be a Java identifier, such as an emoji, falls back to a safe generated name.

Everything runs locally in your browser — no JSON sample is ever uploaded or transmitted to a server. Copy the generated classes into your project, download them as a .txt file, or send the output back into the input to run another tool on it.

FAQ

Does it handle nested objects and arrays?
Yes. Nested objects become their own class (nested or separate, depending on the class layout option) and arrays become a generic java.util.List of the inferred element type.
What happens to a field that is missing from some sample objects?
It is marked optional and, if it is a primitive, upgraded to its wrapper type (Integer, Boolean, Double) so the field can legitimately be null.
Can I use Lombok or Java records instead of manual getters and setters?
Yes. Turn on Lombok @Data for a class annotated with @Data and private fields, or Use a Java record to generate a record with the fields as components — both replace hand-written accessors.
How are field names chosen when a JSON key is not a valid Java identifier?
The key is converted to camelCase; a key that produces an empty or keyword-colliding name falls back to a safe generated name like field or a keyword with a trailing underscore.
Is my JSON uploaded anywhere?
No. Class generation runs entirely in your browser — your JSON sample is never sent to a server.