JSON to Java Class Generator

Generate plain Java classes, with fields, getters and setters, from a JSON sample, one class per nested object.

JSON
Java
Runs locally in your browser

About the JSON to Java Class Generator

Given a JSON document, this generator writes one Java class for each distinct object shape. Field names are converted to camelCase, class names to PascalCase, and types are inferred: whole numbers become Integer, decimals Double, strings String, booleans Boolean, arrays List<T> and nulls Object. Boxed types are used so that a missing field deserialises as null rather than throwing.

Each class has private fields and standard getters and setters, which is what Jackson, Gson and most frameworks expect. An import for java.util.List is added only when a list is present. Nested classes are emitted as separate top-level classes in the same output; split them into files or nest them as static inner classes according to your project style.

The generator does not add annotations, because the right ones depend on your library: add @JsonProperty for Jackson when a JSON key is not a valid Java identifier, or @SerializedName for Gson. For records (Java 16+) or Lombok, use the output as a starting point and strip the accessors.

How to use

  1. Paste a JSON sample on the left.
  2. Set the Root class name.
  3. Copy the classes into your project and add serialisation annotations if your JSON keys use snake_case.

Common questions

Why Integer instead of int?
Boxed types allow null, which is what a JSON field that is absent or null deserialises to. Change to primitives where you are sure the field is always present.
Does it generate Jackson or Gson annotations?
No, the classes are plain so they work with any library. Add annotations only where the JSON key differs from the Java field name.
How are JSON keys with underscores handled?
They are converted to camelCase field names, for example first_name becomes firstName. You will need a mapping annotation or a naming strategy in your mapper.