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, ordouble(whichever fits without loss)booleanβbooleanstringβString(orLocalDate/Instantif it matches ISO 8601)arrayβList<T>, withTinferred 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,toStringauto-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 example | Inferred Java type | Why |
|---|---|---|
42 | int | Fits in 32-bit signed |
10000000000 | long | Exceeds Integer.MAX_VALUE |
3.14 | double | Decimal |
true | boolean | JSON boolean |
"2024-03-15" | LocalDate | ISO 8601 date |
"2024-03-15T10:30:00Z" | Instant | ISO 8601 datetime |
"alice@example.com" | String | Default |
[1, 2, 3] | List<Integer> | Array of ints (boxed in a List) |
{"street": "..."} | new class Street | Nested 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
intwhen the field can be null in JSON. Switch toIntegermanually to allow null values. - Forgetting that the first array element drives the
List<T>type. If your array contains mixed types, the generatedList<Integer>will fail when a String arrives. UseList<Object>for heterogeneous lists. - Expecting
Optionalin 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.
Related tools and guides
- XML to Java POJO β same idea for XML input
- Java Beautifier β clean up the generated output
- Java Online Compiler β try your class in a browser sandbox
- Java String Escape β embed JSON as a Java literal
- ArrayList in Java β for your
List<T>fields - Java Constructors β why the no-arg one matters