JSON to Java POJO Generator

Paste JSON to generate Java POJO classes with optional Lombok @Data, Jackson annotations, and Java 16+ record output.

About This Tool

Hand-writing Java POJO classes for every REST endpoint, configuration file, or message payload is the kind of busywork that eats up hours and breeds copy-paste bugs. This tool reads any JSON document, infers a Java type for every field, recursively builds nested classes for embedded objects, and emits compilable code in the style your project already uses.

The generator supports three output styles. Plain POJO mode produces a traditional class with private fields plus full getX() / setX() accessor methods, ready for any Java version from 8 onwards. Lombok @Data mode strips the boilerplate and lets the Lombok annotation processor synthesize equals, hashCode, toString, getters, and setters at compile time. record mode (Java 16+) emits a single-line immutable carrier — perfect for DTOs and value objects where you do not need mutability.

Type inference follows Java idioms. JSON strings become String, integers become Integer (or Long when the value exceeds 32-bit range), decimals become Double, booleans become Boolean, and arrays become List<T> with a recursively inferred element type. Nested objects are extracted into their own static inner-style classes named after the parent key in PascalCase. If a snake_case JSON key like user_id is converted to the camelCase Java field userId, an optional @JsonProperty("user_id") annotation preserves the wire-format mapping for Jackson deserialization.

Every byte of processing happens in your browser. The JSON is parsed with the native JSON.parse(), all class generation runs as plain JavaScript string operations, and no payload ever crosses a network boundary. That makes the tool safe for internal API responses, customer data, secrets pulled from a vault, or anything else you would not paste into a third-party converter.

If you work across stacks, the same JSON can also be converted to other languages. Try the JSON to Kotlin converter for Android projects, the JSON to C# generator for .NET, or the JSON to Go struct converter for backend services. To clean up the JSON before pasting, use the JSON Formatter to validate and pretty-print first.

How to Use

  1. Paste or type your JSON into the JSON Input panel on the left. The Java output updates automatically as you edit.
  2. Set the Root class name (used for the top-level POJO) and the Package declaration that will appear at the top of the file.
  3. Toggle Lombok @Data if your project includes the Lombok dependency — getters and setters will be omitted in favor of the annotation.
  4. Toggle Jackson @JsonProperty to preserve original snake_case or kebab-case JSON keys when the Java field name differs.
  5. Toggle record (Java 16+) to emit a compact public record definition instead of a class. Lombok is auto-disabled in record mode.
  6. Click Format to pretty-print the JSON input, or Sample to load an example payload.
  7. Click Copy or press Ctrl+Shift+C to copy the generated Java code to your clipboard.

Popular JSON to Java POJO Examples

View all JSON to Java examples →

FAQ

What is a POJO in Java?

POJO stands for Plain Old Java Object. It refers to a regular Java class without any framework-imposed restrictions — no required base class, no required interfaces, and no annotations beyond what you choose to add. POJOs are the default unit of data modeling in Java, used to represent API responses, database rows, configuration entries, and message bodies.

Should I use Lombok or generate getters and setters manually?

Lombok eliminates the visual noise of accessor methods, but it requires the Lombok dependency on your classpath and an IDE plugin to display the generated methods. For new projects or any team that already uses Lombok, @Data is almost always the better choice. For libraries published to Maven Central, codebases with strict no-extra-deps policies, or when targeting environments where annotation processors are blocked, generate getters and setters explicitly.

When should I use record vs class?

Use a record when the type is a transparent carrier of immutable data — a typical DTO, response body, or value object. Records are concise, automatically implement equals, hashCode, and toString, and work well with pattern matching in Java 21+. Use a class when you need mutability, custom validation in setters, inheritance, or when targeting any Java version below 16.

How does the tool handle nested JSON objects?

Each nested JSON object becomes its own Java class, named after the parent key in PascalCase. For example, an "address" field inside a "user" object generates a separate Address class, and the User class references it as a typed field. Deep nesting works the same way — every level of nesting produces a corresponding class. If two distinct objects would resolve to the same class name, a numeric suffix (Address2, Address3, etc.) is appended automatically.

How are snake_case JSON keys converted to Java field names?

Keys written in snake_case (user_name), kebab-case (user-name), or any other separator-based form are normalized to idiomatic camelCase (userName) for the Java field. When the Jackson @JsonProperty toggle is enabled, an annotation is added to preserve the original wire-format key so Jackson can deserialize the unchanged JSON into your camelCase fields.

Why is Lombok disabled when I select the record toggle?

Java records already provide immutable accessors, equals, hashCode, and toString automatically. Adding Lombok's @Data on top would conflict with the record's compiler-generated members and is not supported by Lombok in any case. The toggle disables itself for clarity — switch off record mode first to enable Lombok.

Is my data safe?

Yes. JSON is parsed via the browser's built-in JSON.parse(), and Java source code is assembled with plain JavaScript string operations. No network requests are made, no third-party APIs are contacted, and no input is logged. You can verify this by opening the DevTools Network panel — it stays empty as you paste and convert.

Related Tools