JSON to Java Class Converter - POJOs and Records
Classes for Jackson from a sample payload
Paste a JSON response and get one Java type per object shape: either a class with private fields and
getters/setters, or a record. Field names are camelCase, Java keywords get a trailing underscore
(class becomes class_), and with Jackson annotations on, every field carries
@JsonProperty with the original key, so renaming a field later doesn't break the mapping.
Example: a customer with contacts
Input, with the root type name set to Customer:
{
"customerId": 88123,
"name": "Acme Ltd",
"active": true,
"creditLimit": 2500.75,
"contacts": [
{ "email": "ops@acme.test", "phone": null },
{ "email": "billing@acme.test", "phone": "+64 4 555 0101", "primary": true }
]
} Output with Style set to record:
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public record Customer(
@JsonProperty("customerId") long customerId,
@JsonProperty("name") String name,
@JsonProperty("active") boolean active,
@JsonProperty("creditLimit") double creditLimit,
@JsonProperty("contacts") List<Contact> contacts
) {}
public record Contact(
@JsonProperty("email") String email,
@JsonProperty("phone") String phone,
@JsonProperty("primary") Boolean primary
) {} primary is missing from the first contact, so it is Boolean and comes through as
null rather than false. customerId is long, never
int, because JSON IDs regularly pass 2,147,483,647. Each type is a top-level declaration; put them
in separate files, or nest them as static members of one class.
The class style
The default style writes JavaBeans. Here is Contact from the same input:
public class Contact {
@JsonProperty("email")
private String email;
@JsonProperty("phone")
private String phone;
@JsonProperty("primary")
private Boolean primary;
public String getEmail() { return email; }
public void setEmail(String value) { this.email = value; }
public String getPhone() { return phone; }
public void setPhone(String value) { this.phone = value; }
public Boolean getPrimary() { return primary; }
public void setPrimary(Boolean value) { this.primary = value; }
}
The getter for a wrapper Boolean is getPrimary(). Only primitive
boolean fields get isActive(), which is the JavaBeans rule Jackson follows. No
package line or constructors are generated; add your package and paste the classes in.
Before you commit it
Dates stay String. Change them to Instant or LocalDate and register
JavaTimeModule from jackson-datatype-jsr310 (Spring Boot does this for you). Empty JSON objects
become Map<String, Object>, and fields with mixed or unknown types become
Object. A root-level array produces the item type plus a comment such as
// Root: List<RootItem>. Read it with
mapper.readValue(json, new TypeReference<List<Item>>() {}).
Validating payloads before they reach Jackson? Generate a JSON Schema from the same sample. If your validator stops at draft-07 (everit does), pick that draft in the options.
Same JSON, other languages
Every generator here reads the sample the same way, so a key that is optional or nullable in one language is optional or nullable in the others. Paste the same input into: TypeScript, Zod, Go, Python, Rust, C#, JSON Schema.
Related Tools
JSON to YAML Converter
Convert JSON data to clean, readable YAML format instantly.
JSON to XML Converter
Transform JSON objects and arrays into well-formed XML documents.
JSON to CSV Converter
Flatten JSON arrays into downloadable CSV spreadsheets in one click.
YAML to JSON Converter
Convert YAML configuration files to JSON format instantly.