JSON to Java POJO

Generate a Java POJO class with getters and setters from a JSON document.

JSON Input
Java POJO Output
Java POJO output appears here

Related Tools

Documentation

What is JSON to Java?

This tool converts a JSON sample into plain Java POJOs (Plain Old Java Objects) — private fields with public getters and setters, one class per object level. It's a starting point for a DTO or model class, without pulling in Jackson, Gson, or any specific JSON library.

How it works

The tool infers a type tree from the JSON, then emits every nested object as its own public class, printing child classes before parents. Numbers are inspected at the value level: a whole number in the sample becomes Integer, one with a decimal point becomes Double. Arrays become List<T>, backed by a java.util.List import. Field names are camelCased from the JSON key; if that would collide with a Java keyword (e.g. a JSON key literally named class or int), the field is suffixed with Value so the generated code still compiles. Likewise, if a nested object's class name would collide with a built-in like List, String, or Object, it's renamed with a Model suffix.

Features

  • Standard getter/setter accessor methods generated for every field, following JavaBean conventions
  • Nested JSON objects become separate top-level classes, not inline anonymous types
  • Numbers are typed as Integer or Double based on the actual sample value
  • Reserved keyword field names are automatically renamed to keep the output compilable
  • Library-agnostic output — add Jackson's @JsonProperty or Gson's @SerializedName yourself if you need explicit wire-name mapping

Example

Input: { "id": 101, "username": "alice_dev", "isActive": true, "signupBonus": null, "address": { "city": "Berlin", "zipCode": "10115" }, "tags": ["admin", "beta"] }

Output:

import java.util.List;

public class Address {
    private String city;
    private String zipCode;

    public String getCity() { return city; }
    public void setCity(String city) { this.city = city; }

    public String getZipCode() { return zipCode; }
    public void setZipCode(String zipCode) { this.zipCode = zipCode; }
}

public class Root {
    private Integer id;
    private String username;
    private Boolean isActive;
    private Object signupBonus;
    private Address address;
    private List<String> tags;

    public Integer getId() { return id; }
    public void setId(Integer id) { this.id = id; }

    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }

    public Boolean getIsActive() { return isActive; }
    public void setIsActive(Boolean isActive) { this.isActive = isActive; }

    public Object getSignupBonus() { return signupBonus; }
    public void setSignupBonus(Object signupBonus) { this.signupBonus = signupBonus; }

    public Address getAddress() { return address; }
    public void setAddress(Address address) { this.address = address; }

    public List<String> getTags() { return tags; }
    public void setTags(List<String> tags) { this.tags = tags; }
}

Common errors

A null sample value produces an Object field, since there's no way to infer a concrete type from it — narrow it once you know the real shape. An empty array in the sample has no element to infer from and falls back to List<Object>. If your JSON keys are snake_case, the camelCased field name and the wire key will no longer match, so you'll need a mapping annotation from your JSON library of choice.

Best practices

Treat the generated POJO as a first draft: add validation annotations (Bean Validation's @NotNull, @Size) and an explicit equals()/hashCode() if the class will be used as a map key or in collections. For newer codebases, consider converting the generated fields into a Java record by hand — records give you immutability and generated accessors with far less boilerplate than a classic getter/setter POJO.

Frequently Asked Questions

Does the output include Jackson or Gson annotations?▾

No — the generated POJO is plain Java with private fields and public getters/setters, so it works regardless of which JSON library you use. Add @JsonProperty or Gson's @SerializedName yourself if a field name needs a specific mapping.

How are numbers typed — int or double?▾

The generator inspects the actual sample value: whole numbers (no decimal point) become Integer, and numbers with a fractional part become Double. Double-check fields where the sample happens to be a whole number but could realistically hold decimals later.

What about nested objects and arrays?▾

Each nested object becomes its own public class, and arrays are typed as List with the correct element type, imported from java.util.List.

Why is a field typed as Object?▾

A field is typed Object when its sample value is null or the shape can't be inferred from one example — narrow it to a concrete type by hand once you know what it should be.