JSON to Java
Generate Java POJO classes from JSON instantly. Paste an object above and get private fields with inferred types, constructors and getters/setters — nested objects and arrays mapped to nested classes and List<T>. Local and free.
About this tool
- What is it?
- DataFormatter JSON to Java is a free online tool that converts a JSON object into Java POJO classes — private fields, constructors, getters and setters — with nested objects and arrays mapped to nested classes and List<T>.
- Who is it for?
- Java developers who need model classes for an API response or JSON-structured config and want them derived instantly from a sample.
- What makes DataFormatter's tool different?
- It infers Long vs Double, names files and fields cleanly (avoiding Java keywords), and generates everything locally with no upload and no signup.
Manual tool: JSON to Java — auto-detection is disabled.
Input
0 chars · 0 words · 0 linesPaste or type JSON, Base64, or plain text…
Paste or click a sample above — it will be detected automatically.
Quick start
- Paste a JSON object (for example an example API response) into the editor above.
- A Root class is generated: one private field per key, typed to match the value.
- Copy the class, or Download it as a .java file and drop it into your project.
- Nested objects arrive as static nested classes — import nothing extra.
Type mapping
- Strings map to String, booleans map to Boolean, and integers map to Long.
- Floating-point numbers map to Double, and null maps to a wide Object.
- Arrays map to List<T>; arrays of objects map to List<NestedClass>.
- Objects nested in the root map to static nested classes so one file compiles standalone.
- Java keywords are escaped (class → ClassField) so output always compiles.
JSON to Java example
{ "name": "Ada", "active": true }public class Root {
private String name;
private Boolean active;
public Root() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
}Handy for
Modeling an API response
Paste a real response sample and get the DTO skeleton instantly — fields, types and nested classes exactly matching the payload shape.
Bootstrapping config objects
JSON-based config (service descriptors, feature flags) becomes typed Java objects without hand-writing the mapping layer.
Migrating between service contracts
When a legacy endpoint's JSON drifts from your types, regenerate the class and diff it against the current one with JSON Diff.
Java surprises
JSON to Java requires a JSON object to map onto a class.Why: You pasted a top-level array or a scalar. A Java class maps onto one object, not a list or a value.
Fix: Wrap the object: convert the list you care about by pasting the whole response object, or pick a representative item and paste it directly.
Invalid JSON: Unexpected token '<', "<html>…" is not valid JSONWhy: You pasted HTML (often an error page) instead of JSON — the body started with a tag like <html>.
Fix: Confirm the request actually returned JSON first; the API Client shows status codes and headers so you can spot redirects or 500 pages.
A field name came out different from the JSON keyWhy: Keys with invalid identifier characters or Java keywords were renamed so the generated class compiles.
Fix: That's intentional. If you need the exact JSON name, add an annotation (for example @JsonProperty) in your own code.
Pro tips
- Keep the sample small and flat for the cleanest class — deep nesting produces many nested classes.
- Validate the sample first with the JSON Validator so type inference runs on well-formed input.
- Generate the same sample in TypeScript or Go with JSON to Code to keep multi-language clients in sync.
- Nothing you paste here is sent anywhere, so real payloads are safe to model.
Frequently asked questions
What does JSON to Java generate?
A POJO-style class definition: private fields with inferred Java types, a default constructor, and getter/setter pairs. Nested JSON objects and arrays become nested static classes and List<T> fields respectively.
Which Java types are inferred?
Strings become String, booleans become Boolean, and numbers become Long when they are integers or Double when they have a fractional part — the types you'd actually choose in a POJO.
How are arrays and nested objects handled?
An array becomes a List<…> whose element type is inferred from the first item — a nested object array becomes List<NestedClass>. Objects nested inside the root are emitted as static nested classes on the parent, so the file stays self-contained.
What happens to keys that collide with Java keywords?
They are renamed safely: a field named class becomes ClassField and a class named matching a keyword gets a Value suffix, so the generated code always compiles.
Does my JSON leave the browser?
No. The conversion runs entirely in your browser — nothing you paste is uploaded, which makes it safe to model real API payloads.
What about more languages?
JSON to Code generates TypeScript, C#, Go, Python, Swift, Kotlin and Dart from the same sample, and the JSON Converters hub covers XML, CSV, YAML and Excel targets.