JSON to Java
Generate Java records or classes with getters and setters from JSON online, with Jackson @JsonProperty annotations and List types for arrays.
Something not working, or missing a feature? Send feedback
About the JSON to Java
The JSON to Java converter generates Java records (Java 16+) or classic classes with getters and setters from a JSON sample. Arrays become List types, nested objects become their own types, and Jackson @JsonProperty annotations are added where a Java name differs from the JSON key.
Conversion happens in your browser, so your files and records stay private.
How to use the JSON to Java
- Paste a JSON sample and set the root type name.
- Choose records or classes, and whether to add Jackson annotations.
- Copy the code. Only the root type is public, so move other types into their own files if your project needs one public type per file.
Example
Input
{
"id": 7,
"fullName": "Grace Hopper",
"email": null,
"roles": ["admin"],
"team": { "name": "Compilers", "size": 4 },
"projects": [
{ "name": "COBOL", "year": 1959 },
{ "name": "A-0", "year": 1952, "archived": true }
]
}Result
import java.util.List;
public record User(
long id,
String fullName,
Object email,
List<String> roles,
Team team,
List<Project> projects
) {}
record Project(
String name,
long year,
Boolean archived
) {}
record Team(
String name,
long size
) {}archived is missing from one project, so it is a boxed Boolean that can be null. Records need Java 16+; switch the style to class for older versions.
Common mistakes
- Primitives for nullable values. A long or boolean cannot be null, so a missing value silently becomes 0 or false. Keep the boxed types the converter chose for fields that were null or missing.
- Several public types in one file. Java allows one public top-level type per file. Move each type into its own file, or nest them as static classes inside the root type.
Works well with the JSON to Java
- JSON Formatter: tidy and check the JSON before generating types.
- JSON to TypeScript: generate matching TypeScript interfaces for the front end.
- JSON Validator: find syntax errors in the sample first.
Frequently asked questions
Does this work with Jackson and Gson?
Yes. Jackson reads both records and classes; the @JsonProperty annotations cover keys like snake_case names. Gson reads the classes too; replace @JsonProperty with @SerializedName if you use Gson.
Why are some fields Long or Boolean instead of long or boolean?
Fields that were null or missing in the sample use boxed types, which can hold null. Primitives cannot, and would silently become 0 or false.
Should I use records or classes?
Records are shorter and immutable, and Jackson supports them since 2.12. Use classes for Java versions before 16, or when a framework needs a no-argument constructor and setters.
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.