toolqik

136 · JSON

JSON to Java

Generate Java classes, records or Lombok POJOs with Jackson annotations from JSON.

Runs in your browser
Style
Options
Java code

  

About this tool

Mapping JSON to Java means writing a class per object, a field per key, and getters and setters for each. Paste a JSON example and this generator writes it all: the root class with nested types as static inner classes (so it compiles as one file), List<T> for arrays, and Jackson annotations wherever a JSON key isn’t a valid or conventional Java name.

Three styles

  • POJO: private fields with getters and setters. Works with every framework and Java version.
  • Record (Java 16+): immutable and concise, public record Order(String id, Double total) {}. Jackson 2.12+ deserializes records directly, and Spring Boot 3 handles them out of the box.
  • Lombok: fields plus @Data, @NoArgsConstructor and @AllArgsConstructor; Lombok generates the boilerplate at compile time.

Names and types

  • Keys are converted to camelCase (user_name → userName, postal-code → postalCode), and @JsonProperty("user_name") keeps the mapping to the original key. Java keywords get a trailing underscore (class → class_).
  • Numbers use wrapper types so null is possible: Integer, Long for values beyond 32 bits, Double for decimals. Use BigDecimal for money if precision matters.
  • Mixed or unknown values become Object.

How types are inferred

  • Every object becomes its own named type. Names come from the key (address → Address), and items of an array get the singular (orders → Order).
  • For arrays of objects, all items are merged into one type: a field missing from some items becomes optional, and a field that is sometimes null becomes nullable.
  • Integers and decimals in the same field merge to a decimal type. Fields with mixed types (say a number in one item and a string in another) fall back to the language’s “any” type.
  • Identical nested shapes are reused instead of generating duplicates.

The code is generated from examples, so it can only be as accurate as the sample. Paste a response that includes optional fields and nulls (or several items) for the best result, then check the types against the API documentation. Generated in your browser: your JSON is not uploaded.

Use the classes with Jackson

ObjectMapper mapper = new ObjectMapper()
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Root root = mapper.readValue(json, Root.class);

// A top-level array:
List<Item> items = mapper.readValue(json, new TypeReference<List<Item>>() {});

Using Gson instead? Replace @JsonProperty with @SerializedName, or turn off Jackson annotations.

FAQ

How do I convert JSON to a Java class?

Paste the JSON above and choose POJO, record or Lombok. A class is generated for the root object and every nested object, ready to use with Jackson.

Why are nested classes static inner classes?

So the whole result compiles as a single Root.java file. You can move each class to its own file if you prefer.

Why does it use Integer instead of int?

Wrapper types can hold null, which JSON values often are. Switch to primitives for fields that are always present if you prefer.

Does it work with Gson?

Yes, the classes are plain Java. Gson uses @SerializedName instead of Jackson’s @JsonProperty for renamed fields, so turn off Jackson annotations and add @SerializedName where keys differ.

Can I generate Java records from JSON?

Yes. Choose Record for immutable Java 16+ records. Jackson 2.12 and later can deserialize them.

esc
↑↓ navigate↵ open