Overview
What it does
- • Generates Java classes from JSON fields.
- • Produces getters/setters for each field.
- • Creates child classes for nested objects.
Input requirements
- • JSON must be valid and parseable.
- • Arrays inferred from first element type.
- • Consider naming conventions for generated classes.
Quick Start
- Open /json-to-java
- Paste JSON into the left editor
- Review generated classes in the right panel
- Copy or download the
.javafile
Type Mapping
Primitives
- • string → String
- • integer → int; floating → double
- • boolean → boolean
- • null → Object
Complex
- • array → List<T> (first element based)
- • object → Child class (capitalized)
- • nested object → Separate class + field reference
Collections & Nested Classes
Good Example
{
"items": [{ "id": 1, "name": "Book" }]
}Needs Review
{
"values": [1, "two", true]
}Mixed types; choose Object or normalize to consistent types.
Example
Input JSON
{
"id": 1,
"name": "Book",
"tags": ["tech"],
"author": { "name": "Tom" }
}
Generated Java
public class RootObject {
private int id;
private String name;
private List<String> tags;
private Author author;
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 List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
public Author getAuthor() { return author; }
public void setAuthor(Author author) { this.author = author; }
}
public class Author {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}Tips & Limitations
Recommended
- • Validate JSON and field names
- • Add packages/annotations as needed (e.g., Lombok)
- • Rename classes to meaningful domain names
Limitations
- • Mixed arrays inferred from first element
- • No package/import management beyond List
- • Custom serialization annotations not generated