Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
● JAVA CLASSES · 100% BROWSER-BASED

JSON to Java

Paste a JSON sample and get Java classes, instantly and entirely in your browser. Optional fields, nullability and nested types are inferred from the sample — and anything the sample cannot settle is reported rather than guessed.

JSON sample
TypeScript interface
Type definitions will appear here

Java classes from a sample

Generates classes with @JsonProperty annotations and boxed types so a missing value is distinguishable from zero.

Each public class needs its own file when you use this in a project.

What a sample cannot tell you

Types are inferred from one sample. A field absent from your sample will be absent from the output, and a field that happens to hold only whole numbers will be typed as an integer even if it can hold decimals. Paste the widest sample you have. For a guarantee rather than an inference, start from a JSON Schema.

What Java output looks like

Generated from two sample records, one of which has an extra field and a null. This is the actual output, not an illustration:

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

public class Root {
    @JsonProperty("id")
    public Long id;

    @JsonProperty("userName")
    public String userName;

    @JsonProperty("isActive")
    public Boolean isActive;

    @JsonProperty("score")
    public Double score;

    @JsonProperty("tags")
    public List<String> tags;

    @JsonProperty("address")
    public Address address;

    @JsonProperty("lastSeen")
    public String lastSeen;

    @JsonProperty("nickname")
    public String nickname;
}

public class Address {
    @JsonProperty("city")
    public String city;

    @JsonProperty("postcode")
    public Object postcode;
}

The three things that differ by language

Large integers

Large integers become Long. Boxed types are used throughout so a missing value is null rather than silently 0 — the distinction a primitive would erase.

Optional against nullable

Every field is boxed, which is the only way Jackson can tell "absent" from "zero" without extra configuration.

Names that are not identifiers

@JsonProperty maps each field to its original key. Each public class needs its own file when you use this in a project.

Convert the same JSON to