JSON to Java POJO / Record Converter

How the converter works

The converter parses your JSON object, infers a Java type for each value, and generates one Java class per nested object. Types are inferred as follows:

  • number β†’ int, long, or double (whichever fits without loss)
  • boolean β†’ boolean
  • string β†’ String (or LocalDate/Instant if it matches ISO 8601)
  • array β†’ List<T>, with T inferred from the first element
  • Nested object β†’ a new Java class, named from the field

Everything runs in your browser β€” no network request, no data leaves the page.

Which output style should I use?

  • Record β€” Java 16+. Immutable, concise, with equals, hashCode, toString auto-generated. Best default for DTOs.
  • POJO β€” classic class with private fields, getters and setters. Mutable. Compatible with Java 8+ and every framework under the sun.
  • Lombok β€” same as POJO but with @Data; zero boilerplate if your project already uses Lombok.

Type inference explained

JSON value exampleInferred Java typeWhy
42intFits in 32-bit signed
10000000000longExceeds Integer.MAX_VALUE
3.14doubleDecimal
truebooleanJSON boolean
"2024-03-15"LocalDateISO 8601 date
"2024-03-15T10:30:00Z"InstantISO 8601 datetime
"alice@example.com"StringDefault
[1, 2, 3]List<Integer>Array of ints (boxed in a List)
{"street": "..."}new class StreetNested object

Using the output with Jackson

For runtime deserialization, Jackson works out of the box with all three output styles:

ObjectMapper mapper = new ObjectMapper();

// POJO or Lombok
User user = mapper.readValue(json, User.class);

// Record (Jackson 2.12+)
Point p = mapper.readValue(json, Point.class);

Using the output with Gson

Gson gson = new Gson();
User user = gson.fromJson(json, User.class);

Gson requires a no-arg constructor β€” which our POJO output provides implicitly. For records, you'll need GsonBuilder with the RecordTypeAdapterFactory.

Build-time generation from JSON Schema

If you need to generate Java classes as part of a build (continuous integration, code generation pipeline), this browser tool is the wrong fit. Use jsonschema2pojo with Maven:

<plugin>
  <groupId>org.jsonschema2pojo</groupId>
  <artifactId>jsonschema2pojo-maven-plugin</artifactId>
  <version>1.2.2</version>
  <configuration>
    <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
    <targetPackage>com.example.model</targetPackage>
  </configuration>
</plugin>

Paste your JSON here for a first draft, then move to schema-based generation once the model stabilizes.

Common mistakes to avoid

  • Missing no-arg constructor. Most frameworks (Jackson 2.x, Gson, JPA) want one. Our POJO output includes an implicit one; records don't need it (they use canonical constructor).
  • Using int when the field can be null in JSON. Switch to Integer manually to allow null values.
  • Forgetting that the first array element drives the List<T> type. If your array contains mixed types, the generated List<Integer> will fail when a String arrives. Use List<Object> for heterogeneous lists.
  • Expecting Optional in fields. Jackson discourages it. Keep your fields as regular types and wrap only at the API boundary.
  • Sensitive data in the JSON sample. The JSON never leaves your browser, but double-check the sample doesn't leak credentials before you copy-paste.