FormatterHQ

JSON to Java POJO Generator

Generate Java POJOs from a JSON sample: private fields with getters and setters, one class per object shape, and optional Jackson (de)serialization code.

Input JSON
Output JAVA
Ready.

How to use the JSON to Java

  1. Paste your JSON sample (an object, or an array of objects) into the Input editor, or use Sample, Upload file or Load URL, or press Sample to try one.
  2. Set the Top-level class name, for example Task; it is converted to PascalCase. Nested types are named after their property keys.
  3. Tick Types only (no helpers) for plain POJOs, or leave it off to get Jackson annotations and a Converter class.
  4. Press Generate (it also re-runs automatically as you edit), then use Copy or Download.

JSON to Java: generate POJO classes

Mapping a JSON API to Java usually means writing a class per object, choosing field types, and adding getters and setters. This JSON to Java generator does it for you. It analyzes the sample with quicktype and writes one POJO per distinct object shape, with private fields and JavaBean accessors. Types are chosen carefully: whole numbers become long, decimals double, arrays List<T>, and ISO date strings OffsetDateTime.

Example

{
  "id": 42,
  "title": "Write docs",
  "done": false,
  "priority": 2.5,
  "tags": ["docs"],
  "owner": { "name": "Ada", "email": null },
  "due": "2026-10-01T09:00:00Z",
  "subtasks": [
    { "title": "Outline", "estimate": 2 },
    { "title": "Draft" }
  ]
}

With Types only checked, the Subtask class looks like this:

package io.quicktype;

public class Subtask {
    private String title;
    private Long estimate;

    public String getTitle() { return title; }
    public void setTitle(String value) { this.title = value; }

    public Long getEstimate() { return estimate; }
    public void setEstimate(Long value) { this.estimate = value; }
}

Notice Long rather than long: the property is missing from one subtask, so it must be nullable, and a primitive cannot hold null. Required numeric fields such as Task.id use the primitive long. The owner.email field, which is null in the sample, is typed as Object.

Types only vs. Jackson helpers

With Types only off, the output adds everything needed to read and write JSON with Jackson:

  • @JsonProperty("...") annotations on accessors, so JSON keys map to the right fields even when names differ (user_name is exposed as getUserName()).
  • A Converter class with fromJsonString(String) and toJsonString(Task), preconfigured with an ObjectMapper and date-time parsing for OffsetDateTime.
  • A comment listing the Maven dependencies: jackson-databind and jackson-datatype-jsr310.

Use the helpers for a quick standalone parser. In a Spring Boot application, which already configures Jackson, the POJOs alone are usually enough, but keep the @JsonProperty annotations when JSON keys are not camelCase.

Unknown properties

By default Jackson's ObjectMapper throws UnrecognizedPropertyException when the JSON contains a key that has no matching field, which happens as soon as an API adds a new property. If your client should tolerate additions, annotate the classes with @JsonIgnoreProperties(ignoreUnknown = true) or disable DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES on the mapper. Spring Boot's auto-configured mapper already disables it.

Type mapping

JSONJava
integerlong / Long if optional
decimaldouble / Double
booleanboolean / Boolean
ISO date-time stringOffsetDateTime
arrayList<T>
objecta new class named after the key
null only / mixedObject

Tips

  • Package name: the output uses io.quicktype; replace it with your own package.
  • One file per class: the output marks each class with a comment like // Subtask.java. Split them into separate files, since Java allows one public top-level class per file.
  • Records: on Java 16+ you can turn simple POJOs into record Subtask(String title, Long estimate) {}; Jackson 2.12+ supports records.
  • Lombok: if you use Lombok, replace the accessors with @Data or @Getter/@Setter.
  • Representative samples give better types: include records where optional fields are present and absent.

Format the generated code with the Java Formatter. Have XML instead of JSON? XML to Java works the same way. Need to fix the input first? Try the JSON Formatter. All generation runs in your browser.

Frequently asked questions

Does the generated Java code work with Jackson?
Yes. With Types only off, it includes @JsonProperty annotations and a Converter class built on Jackson’s ObjectMapper. With Types only on, you get plain POJOs that Jackson can still map when JSON keys match the property names.
Why are some fields Long instead of long?
Fields that can be missing or null must be able to hold null, which primitives cannot. Required numbers use primitives, optional ones use wrapper types.
Can I use Gson instead of Jackson?
Yes. Use Types only and add Gson’s @SerializedName annotations where JSON keys differ from Java field names.
How do I change the package name?
Replace the io.quicktype package declaration at the top of each class with your own package.
How are dates handled?
ISO 8601 date-time strings become java.time.OffsetDateTime. The Jackson helpers include parsing code; with plain POJOs, register the JavaTimeModule in your ObjectMapper.

Last updated September 26, 2026

Related tools

XML to Java Generate Java POJO classes with getters and setters from a XML sample instantly, with nested types detected automatically. JSON to JavaScript PropTypes Generate JavaScript PropTypes React PropTypes definitions from a JSON sample instantly, with nested types detected automatically. JSON to JSON Schema Generate JSON Schema a JSON Schema document from a JSON sample instantly, with nested types detected automatically. JSON to Kotlin Generate Kotlin data classes from a JSON sample instantly, with nested types detected automatically. JSON to Laravel Model & Migration Generate a Laravel Eloquent model ($fillable, casts, relations) and a matching migration from a sample JSON record. JSON to Mongoose Schema Generate a Mongoose schema and model from a sample JSON document, detecting Date, ObjectId, arrays and nested objects. JSON to Objective-C Generate Objective-C classes with properties from a JSON sample instantly, with nested types detected automatically. JSON to PHP Generate PHP classes with typed properties from a JSON sample instantly, with nested types detected automatically. JSON to Pike Generate Pike classes from a JSON sample instantly, with nested types detected automatically. JSON to Python Generate Python dataclasses with type hints from a JSON sample instantly, with nested types detected automatically. JSON to Ruby Generate Ruby Dry::Struct classes from a JSON sample instantly, with nested types detected automatically. JSON to Rust Generate Rust structs with Serde derives from a JSON sample instantly, with nested types detected automatically.