JSON to JavaONLINE

Generate Java types or models from sample JSON and download .java code.

1 MiB per input · Ctrl / ⌘ + Enter to run

quicktype infers shapes from a sample up to 128 Ki characters. Review field optionality, names, and type choices before adding generated code to your project.

Result
Ready. Paste input, then run the tool.
Your JSON stays in your browser. Core processing happens locally.
THE PRACTICAL GUIDE

Create Java model classes from a JSON response

JSON to Java infers Java model code for an observed JSON structure. It is a starting point for mapping API responses into a typed application.

When should you use it?

  • Prototype models for a Java API client.
  • Inspect nested object structure as classes.
  • Create a draft DTO from a test response.
WORKED EXAMPLE

Example: infer Java fields from JSON

This abbreviated example shows the inferred name and active fields in Java. The full generated file includes imports and helpers and may change with generator versions; review it before adding it to a project.

Sample JSON
{"name":"Alex","active":true}
Illustrative model excerpt
public class Root {
    private String name;
    private boolean active;
    // getters and setters follow
}

Review the generated model with its serializer

A Java model and its JSON binding library work together. Property annotations, accessors, imports, and conversion helpers can be as important as the field declarations. Keep the complete generated file when testing the result, then adapt its organization to your project. An abbreviated example on this page illustrates the shape rather than a standalone Java application.

Check nullable numbers and domain types

A primitive numeric field cannot represent null, while a wrapper type can. A sample that always includes a value does not prove that the API always supplies it. Review optionality, integer range, decimal precision, and date handling against the contract. Money and identifiers may need deliberate domain types rather than whatever the first example happens to suggest.

IN PRACTICE

How do I generate Java DTO classes from a JSON response?

Paste a JSON object and generate Java source, then adapt the classes to your project’s package and serializer. The generated model reflects observed properties and nested types, making it useful for a first integration pass.

Illustrative Java model fields

java
public class Root {
    private String name;
    private boolean active;
    // Generated accessors and mapping code follow.
}

The quicktype target emits additional converter code and Jackson-related imports. Review dependencies, package names, and null cases before compiling.

No. Optional or variant fields absent from the sample cannot be inferred reliably. Confirm the shape against the provider’s contract and more than one response.

BEFORE YOU USE THE RESULT

What should you check before using the result?

Check package layout, naming, nullable fields, serialization library expectations, and missing cases before integration. A sample cannot establish all server variants.

Understand JSON syntax

Technical reference: quicktype model generation documentation

THE JSON FIELD GUIDE
All guides