JSON to Java
Convert any JSON object or array into clean Java POJO classes instantly. Generates private fields with correct Java types, getters and setters, Jackson annotations for camelCase JSON key mapping, Lombok @Data support to eliminate boilerplate, nested class decomposition, and List types for JSON arrays. Runs entirely in your browser — no data transmitted.
Convert any JSON object or array into clean Java POJO classes instantly. Generates private fields with correct Java types, getters and setters, Jackson annotations for camelCase JSON key mapping, Lombok @Data support to eliminate boilerplate, nested class decomposition, and List types for JSON arrays. Runs entirely in your browser — no data transmitted.
This tool is designed to provide a seamless experience for developers by handling complex operations directly in your browser with maximum speed and security.
A JSON to Java converter reads a JSON object or array and generates Java class definitions that represent the same data structure — either as traditional Plain Old Java Objects (POJOs) with private fields, public getters and setters, and optional Jackson serialisation annotations, or as Lombok-annotated classes that eliminate the getter and setter boilerplate entirely.
A POJO in Java is simply a class with no special framework requirements — no mandatory superclass, no required interface implementations, just private fields and public accessor methods. The POJO pattern for JSON mapping exists because Java's strong typing requires that you define the structure of your data explicitly before you can work with it in a type-safe way. Jackson, the most widely used Java JSON library (and the default in Spring Boot), maps JSON keys to Java class fields by name during deserialisation. When you call objectMapper.readValue(jsonString, User.class), Jackson reflects on the User class, finds a field matching each JSON key, and sets its value.
The non-trivial part of writing POJOs from JSON by hand is that Java is genuinely verbose. A class representing a JSON object with eight fields requires eight private field declarations, eight getter methods, and eight setter methods — plus a constructor or builder, if you want immutability or a fluent construction API. For a JSON response with three levels of nesting and thirty total fields, writing that by hand takes twenty to thirty minutes with no interesting engineering decisions involved. Every minute of it is mechanical.
Lombok eliminates the getter and setter problem entirely. Add @Data to a Lombok-annotated class and the Lombok annotation processor generates all getters, all setters, equals(), hashCode(), and toString() at compile time. The class definition is just the field declarations. @Builder generates a builder pattern. @Value makes the class immutable. Jackson integrates cleanly with Lombok — the generated getters are what Jackson uses for serialisation, and the generated setters are what Jackson uses for deserialisation. You get the full Jackson integration with a fraction of the source code.
The type mapping from JSON to Java requires specific decisions that this tool handles correctly. JSON strings become String. JSON integers become int or Integer depending on whether you want primitives or boxed types. JSON floating-point numbers become double or Double. JSON booleans become boolean or Boolean. JSON null requires boxed types (Integer rather than int) because Java primitives cannot hold null. JSON arrays become List with a typed generic parameter. Nested JSON objects generate their own Java class definition referenced by name in the parent class.
This tool reads a JSON object or array and generates Java class definitions representing the same data structure, ready to use with Jackson's ObjectMapper for deserialising API responses or serialising data back to JSON in your Java application. The type mapping produces idiomatic Java types for every JSON value type. JSON strings become String fields. JSON integer values become int fields (or Integer for fields that may be null, since Java primitives cannot hold null values). JSON floating-point numbers become double fields (or Double for nullable cases). JSON booleans become boolean fields (or Boolean for nullable cases). JSON null values in your sample, or fields absent from some records in an array input, are typed with boxed types (Integer, Double, Boolean) rather than primitives, and are annotated to allow null during deserialisation. JSON arrays generate List fields with a typed generic parameter. An array of strings becomes List, an array of integers becomes List, and an array of nested objects becomes List where NestedType is a separately generated inner class or top-level class. This typed List approach is what Jackson expects for correct deserialisation of JSON arrays — using raw List or List causes Jackson to deserialise array elements as LinkedHashMap instances rather than typed objects, which is a common source of ClassCastException. Each generated class includes private field declarations, a no-argument constructor (required by Jackson for deserialisation), getter methods following the getFieldName() convention, and setter methods following the setFieldName() convention. Jackson uses the getter methods for serialisation and the setter methods for deserialisation by default, based on the JavaBeans naming convention. When Jackson annotations are enabled, the generator adds @JsonProperty("jsonKeyName") to each field whose Java name differs from the JSON key. For camelCase JSON keys like firstName or isActive where the Java field name matches exactly, no annotation is needed. For JSON keys that conflict with Java reserved words, contain hyphens or underscores, or use a naming convention that does not map directly to the Java field name, @JsonProperty with the exact JSON key string ensures correct mapping. When Lombok mode is enabled, the class is annotated with @Data which instructs Lombok's annotation processor to generate all getter methods, all setter methods, equals(), hashCode(), and toString() at compile time. The source file contains only the field declarations and the @Data annotation — significantly shorter and easier to maintain than the equivalent class with manually written accessors. An optional @Builder annotation adds a fluent builder API for constructing instances without calling setters individually.
1. Paste your JSON into the input editor. Use a real API response sample if you have one — the more representative your input, the more accurate the generated Java types will be. If you have multiple response samples with varying fields, consider merging them into a JSON array so the tool can detect optional fields and type them with boxed types (Integer, Boolean) rather than primitives.
2. Select your output mode. Choose Standard POJO for classes with full getter and setter methods — compatible with any Java version from Java 8 onward with no external dependencies beyond Jackson. Choose Lombok for classes annotated with @Data that require lombok as a compile dependency but eliminate all getter and setter boilerplate. Choose Java Record (Java 16+) if you want immutable data carriers using the record keyword.
3. Toggle Jackson Annotations if your JSON keys do not map directly to Java field names — for example, snake_case JSON keys, hyphenated keys, or keys that conflict with Java reserved words. With this toggle on, @JsonProperty annotations are added wherever the mapping is non-trivial.
4. Click Convert to Java Bean. The output panel shows the complete Java class hierarchy — nested classes either as inner static classes within the root class or as separate top-level class definitions depending on your preference setting.
5. Review the generated types carefully before using in production. Check numeric fields — the tool uses int for integer-looking values, but if the field could hold null in some API responses, you need Integer (boxed). Check that List is used with the correct generic type parameter for array fields. Check that any field typed as Object is intentional — this happens when an array contains mixed types or when a value is null in your entire sample.
6. Copy the output and create a new Java source file in your project for each generated class. Add the appropriate package declaration at the top of each file — the generator does not know your package structure. Add the Jackson dependency to your pom.xml or build.gradle if you are using Jackson annotations, and the Lombok dependency if you are using Lombok mode. Use new ObjectMapper().readValue(jsonString, YourRootClass.class) to deserialise your JSON into the generated class hierarchy.
Java's type system is one of its greatest strengths for large, long-lived applications. The compiler catches entire categories of bugs at build time that would only surface at runtime in dynamically typed languages. JSON integration in Java requires that you materialise that type system — write out the class structure that mirrors your JSON — before you can benefit from any of it. The raw Map approach — deserialising JSON into Map and casting values manually — is technically possible but represents the worst of both worlds. You lose compile-time type safety (every value is Object), you lose IDE autocompletion (no typed fields to autocomplete), and you still have to write casting code everywhere: (String) user.get("name"), (Integer) user.get("age"). The casts are wrong often enough that experienced Java developers avoid this pattern entirely for anything beyond quick one-off scripts. The verbosity of Java POJO boilerplate is the reason Lombok exists and why it is installed in virtually every modern Java project. A seven-field POJO without Lombok is sixty to seventy lines: seven field declarations, seven getters, seven setters, a constructor, equals, hashCode, and toString. The same class with @Data is twelve lines: the class declaration, seven field declarations, and the annotation. The generated bytecode is identical — Lombok's annotation processor produces exactly the same bytecode as hand-written accessors. The difference is entirely in source code maintenance burden. Spring Boot applications compound this because every request body, every response type, every JPA entity, and every DTO (Data Transfer Object) in a Spring Boot application is a POJO or a Lombok-annotated equivalent. A typical Spring Boot service integrating three external APIs might have thirty to fifty model classes. Writing those by hand from API documentation or JSON response samples is a full day of mechanical work. Generating them from actual API responses takes minutes, and the generated classes are derived from real data rather than documentation that may be out of date. The Jackson @JsonProperty annotation is the specific piece that most developers get wrong when writing POJOs manually. Jackson's default naming strategy maps Java camelCase field names to JSON camelCase keys — firstName maps to firstName, isActive maps to isActive. This works perfectly until you encounter a JSON key that uses snake_case (first_name), a key with a hyphen (X-Request-Id), a key that is a Java reserved word (class, interface, default), or a key whose capitalisation does not match Jackson's inferred getter name. Each of these requires an explicit @JsonProperty annotation, and missing one means that field silently deserialises as null without any error. This tool adds @JsonProperty annotations wherever the mapping is non-trivial, preventing that class of silent data loss.
Correct Java type mapping — String | int | double | boolean | Integer (boxed for nullable) and List with generic type parameter
Jackson @JsonProperty annotations generated for all fields — prevents silent null deserialisation failures
Lombok @Data mode eliminates all getter & setter & equals & hashCode and toString boilerplate
Nested JSON objects generate separate named Java class definitions with their own Jackson annotations
List with correct generic type parameter for JSON arrays — prevents ClassCastException from raw List usage
No-argument constructor included for Jackson deserialisation compatibility
Java 16+ Record output mode for immutable data carrier classes
Runs entirely in your browser — zero data transmitted & no IDE or JDK required
Generating Java POJO classes for deserialising REST API responses in a Spring Boot application
Scaffolding Jackson-annotated model classes when integrating a new third-party API into a Java backend service
Creating DTO classes for a Spring Boot controller request body or response type from a JSON API specification
Generating Lombok-annotated model classes for a Java microservice that consumes JSON from a message queue
Building typed Java classes for parsing JSON configuration files in a Java application or library
Creating Java model classes for a Spring Data REST or Spring MVC application from an existing JSON schema
Prototyping Java data models from a real API response before writing full service layer code
Generating Java record classes for immutable API response models in a Java 16+ application
Example Input
{
"id": 1,
"name": "Priya Singh",
"email": "priya@techcorp.io",
"role": "Principal Engineer",
"yearsExperience": 15,
"salary": 185000.00,
"isActive": true,
"joinedAt": "2019-03-12",
"reportsTo": null,
"skills": ["Java", "Spring Boot", "PostgreSQL", "System Design"],
"profile": {
"bio": "15 years in distributed systems and data infrastructure.",
"timezone": "Asia/Kolkata",
"githubHandle": "priyasingh-eng"
}
}Example Output
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class User {
@JsonProperty("id")
private int id;
@JsonProperty("name")
private String name;
@JsonProperty("email")
private String email;
@JsonProperty("role")
private String role;
@JsonProperty("yearsExperience")
private int yearsExperience;
@JsonProperty("salary")
private double salary;
@JsonProperty("isActive")
private boolean isActive;
@JsonProperty("joinedAt")
private String joinedAt;
@JsonProperty("reportsTo")
private String reportsTo; // nullable — consider Integer or Object
@JsonProperty("skills")
private List skills;
@JsonProperty("profile")
private Profile profile;
// Getters and Setters
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
public int getYearsExperience() { return yearsExperience; }
public void setYearsExperience(int yearsExperience) { this.yearsExperience = yearsExperience; }
public double getSalary() { return salary; }
public void setSalary(double salary) { this.salary = salary; }
public boolean isActive() { return isActive; }
public void setActive(boolean isActive) { this.isActive = isActive; }
public String getJoinedAt() { return joinedAt; }
public void setJoinedAt(String joinedAt) { this.joinedAt = joinedAt; }
public String getReportsTo() { return reportsTo; }
public void setReportsTo(String reportsTo) { this.reportsTo = reportsTo; }
public List getSkills() { return skills; }
public void setSkills(List skills) { this.skills = skills; }
public Profile getProfile() { return profile; }
public void setProfile(Profile profile) { this.profile = profile; }
}
public class Profile {
@JsonProperty("bio")
private String bio;
@JsonProperty("timezone")
private String timezone;
@JsonProperty("githubHandle")
private String githubHandle;
// Getters and Setters
public String getBio() { return bio; }
public void setBio(String bio) { this.bio = bio; }
public String getTimezone() { return timezone; }
public void setTimezone(String timezone) { this.timezone = timezone; }
public String getGithubHandle() { return githubHandle; }
public void setGithubHandle(String githubHandle) { this.githubHandle = githubHandle; }
}com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of MyClass — no suitable constructor
Fix: Jackson requires a no-argument constructor to deserialise JSON into a POJO using the default property-based deserialisation. If you have a Lombok @Builder annotation without @NoArgsConstructor, or a custom constructor that takes parameters, Jackson cannot instantiate the class. Add @NoArgsConstructor to the Lombok-annotated class alongside @Builder, or add an explicit public MyClass() {} no-arg constructor to the standard POJO.
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field — field in JSON not found in class
Fix: Jackson found a JSON key that has no corresponding field in your Java class. Either the API added a new field that is not in your generated class, or there is a capitalisation mismatch between the JSON key and your @JsonProperty annotation. Add the missing field to your class, or add @JsonIgnoreProperties(ignoreUnknown = true) at the class level to silently ignore JSON fields that have no corresponding Java field — the latter is the pragmatic choice for API responses that may evolve.
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class MyNestedClass
Fix: A List field is declared as raw List or List instead of List. Jackson deserialises JSON array elements as LinkedHashMap when the list element type is unspecified or Object. Change the field declaration to List where NestedClass is the specific Java class you expect the array elements to deserialise into. This requires the nested class to also have Jackson-compatible constructors and field annotations.
java.lang.NullPointerException when accessing a field — primitive field receives null from JSON
Fix: A field declared as a Java primitive (int, double, boolean) received a null value from the JSON. Jackson cannot assign null to a primitive and either throws or silently uses the default value (0 for int, false for boolean) depending on DeserializationFeature settings. Change the field type from int to Integer, from double to Double, or from boolean to Boolean — boxed types accept null values. Enable DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES in your ObjectMapper configuration if you want an explicit exception rather than silent default assignment.
The Lombok @Data annotation is not generating getters and setters — methods missing at compile time
Fix: Lombok's annotation processing must be enabled in your build system and IDE. For Maven, add the lombok dependency with provided scope and ensure the maven-compiler-plugin has annotation processing enabled. For Gradle, add lombok to compileOnly and annotationProcessor configurations. In IntelliJ IDEA, install the Lombok plugin and enable annotation processing in Settings > Build > Compiler > Annotation Processors. Without these configurations, Lombok annotations are compiled but the annotation processor that generates the code does not run.
Using int instead of Integer for a field that can be null — Java primitives (int, double, boolean) cannot hold null values. If a JSON field is null in some API responses, Jackson will throw a NullPointerException or a MismatchedInputException when it tries to assign null to an int field. The fix is to use the boxed type Integer, Double, or Boolean for any field that could be null. The generator uses primitives for fields with non-null values in your sample and boxed types for fields that are null — but if your sample does not include a null case for a field that can be null in production, you need to make that change manually.
Forgetting to add the package declaration to the generated class file — the generator produces the class body without a package statement because it does not know your project's package structure. Every Java source file in a real project must start with a package declaration matching the directory path where the file lives: package com.yourcompany.yourapp.model; Without it, the class compiles into the default package, which causes access issues and conflicts with IDE project conventions.
Using raw List instead of typed List for array fields — Jackson deserialises JSON arrays into List fields. If the field is declared as raw List or List without a generic type, Jackson uses its default type for unknown elements, which is LinkedHashMap for objects and String for strings. Accessing elements from a raw List that you expected to be your typed model class will throw a ClassCastException at runtime. Always use List, List, List for typed deserialisation.
Not adding the no-arg constructor when using Jackson — Jackson's default deserialisation mechanism requires a no-argument constructor to instantiate the class before setting field values via setter methods. If you use Lombok's @Builder annotation alone without @NoArgsConstructor, or if you define a custom constructor that takes arguments without also defining a no-arg constructor, Jackson will throw an InvalidDefinitionException: No suitable constructor found. Either add @NoArgsConstructor explicitly alongside @Builder, or add @JsonCreator to your custom constructor.
Keeping the generated class in one file when it has multiple top-level classes — Java only allows one public top-level class per source file, and it must match the filename. If the generator produces both a User class and a Profile class as top-level public classes, you need to split them into User.java and Profile.java, or make Profile a public static inner class inside User. Keeping multiple public top-level classes in a single file will cause a compile error.
JSON Cheatsheet
Interactive reference guide for valid JSON syntax, data types, parsing/stringifying methods, schema validation rules, and language integrations.
Regex Cheatsheet
Interactive guide to Regex anchors, character classes, quantifiers, lookarounds, capturing groups, and search flags.
HTTP Headers Cheatsheet
Complete guide to standard and security HTTP headers including Authorization, CORS control, caching policies, and CSP directives.
SQL Cheatsheet
Complete guide to SQL statements including SELECT queries, WHERE filters, aggregate functions, JOIN types, and DDL commands.
Does it support Lombok annotations?
Yes. Lombok mode generates classes annotated with @Data, which instructs Lombok's annotation processor to generate all getter methods, all setter methods, equals(), hashCode(), and toString() at compile time. The source file contains only field declarations and the annotation — significantly shorter than the equivalent class with hand-written accessors. An optional @Builder annotation adds a fluent builder API. For immutable classes, @Value (Lombok's immutable variant of @Data) makes all fields private and final and omits setters. All Lombok-generated code is fully compatible with Jackson's ObjectMapper for deserialisation, since Jackson uses the generated getter and setter methods by convention.
What is a POJO and why does Java JSON mapping use this pattern?
POJO stands for Plain Old Java Object — a class with no special framework requirements, just private fields and public accessor methods. Jackson's ObjectMapper maps JSON keys to Java class fields using reflection, looking for getter and setter methods that follow the JavaBeans naming convention: getFieldName() for reading and setFieldName(value) for writing. This convention-based mapping means Jackson can deserialise any POJO without any annotations, as long as the JSON key names match the Java field names exactly. Annotations like @JsonProperty are needed only when the JSON key name does not match the Java field name.
How do I handle unknown fields in the API response that are not in my generated class?
By default, Jackson throws an UnrecognizedPropertyException when it encounters a JSON key that has no corresponding field in your Java class. This is a strict-by-default behaviour that catches typos and schema mismatches. For API responses that may include fields you do not need, add @JsonIgnoreProperties(ignoreUnknown = true) at the class level. This tells Jackson to silently discard any JSON key it cannot map to a field, which is the pragmatic choice for third-party API integration where you only care about a subset of the response fields.
Can I use the generated class with Spring Boot directly?
Yes. Spring Boot uses Jackson's ObjectMapper as its default JSON serialiser and deserialiser for REST controllers. A @RequestBody parameter in a Spring MVC controller is automatically deserialised from the request body JSON into your generated class using Jackson. A @ResponseBody or ResponseEntity return type is automatically serialised to JSON from your generated class. No additional configuration is needed — Spring Boot auto-configures an ObjectMapper that works with any correctly structured POJO or Lombok-annotated class.
Should I use int or Integer for numeric fields?
Use int (primitive) for fields that are never null in your API response — it is more memory-efficient and avoids unnecessary boxing and unboxing overhead. Use Integer (boxed) for fields that can be null in some API responses, including fields that are optional, fields that represent missing or unknown values, and fields that are null in edge cases your sample may not cover. A primitive int field that receives a null value from Jackson will either throw a MismatchedInputException or silently use 0 as the default, depending on your ObjectMapper configuration. Neither behaviour is what you usually want — Integer with a null check is explicit and correct.
What is the difference between @JsonProperty and @JsonAlias?
@JsonProperty defines the canonical JSON key name for a field — both for deserialisation (reading JSON) and serialisation (writing JSON). If you set @JsonProperty("first_name") on a field named firstName, Jackson reads from first_name in JSON and writes first_name to JSON. @JsonAlias defines alternative key names accepted during deserialisation only — the field accepts both the primary name and the alias when reading JSON, but always writes using the primary name. Use @JsonProperty when you want a consistent one-to-one mapping. Use @JsonAlias when you need to accept JSON from multiple sources that use different key names for the same field.
How does the tool handle date and time fields?
Date and time values in JSON are typically represented as strings — ISO 8601 formatted values like '2019-03-12' or '2024-07-15T14:30:00Z'. The generator types these fields as String because it cannot determine from the value alone whether you want a Java String, a java.time.LocalDate, a java.time.LocalDateTime, or a java.time.Instant in your model. To use typed date fields, change the field type from String to the appropriate java.time type and configure your Jackson ObjectMapper with a JavaTimeModule: mapper.registerModule(new JavaTimeModule()). Use @JsonFormat(pattern = "yyyy-MM-dd") on the field if your date format differs from Jackson's defaults.
Is my JSON data sent to any server?
No. The entire conversion runs in JavaScript in your browser. Your JSON is never transmitted to any external server, never logged, and never stored anywhere outside your local browser tab. Open your browser's network inspector before pasting any data and you will see zero outbound requests carrying your JSON. This makes the tool safe for real API response payloads, internal service data, customer records, or any JSON you would not want routed through a third-party service.
How to Convert JSON to Dart Classes for Flutter – Complete In-Depth Guide (2026)
How to convert JSON to Dart classes for Flutter in 2026. In-depth guide covering Dart model best practices, null safety, immutable classes, code generation with json_serializable & freezed, Flutter integration with Riverpod, and real-world architecture tips from a Principal Software Engineer with 15+ years experience.
What is JSON? How to Format, Validate & Use It (Complete Guide 2026)
What is JSON? How to Format, Validate & Use It (Complete Guide 2026). In-depth explanation of JSON syntax, real-world use cases, formatting best practices, common mistakes, advantages, disadvantages, and expert tips from a Principal Software Engineer with 15+ years experience.
How to validate JSON online (step-by-step guide)
Invalid JSON can break your application. Follow this guide to quickly validate and fix your JSON data.
Recent Activity
No recent activity