CalcCafe

JSON to Java

Paste JSON and instantly get Java class definitions with inferred field types for nested objects and arrays.

Example

Given this JSON:

{
 "id": 7,
 "name": "Ada",
 "address": { "city": "London" }
}

JSON to Java emits:

public class Root {
  private int id;
  private String name;
  private Address address;

  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 Address getAddress() { return address; }
  public void setAddress(Address address) { this.address = address; }
}

public class Address {
  private String city;

  public String getCity() { return city; }
  public void setCity(String city) { this.city = city; }
}

How it works

It parses your JSON, infers a Java type for each value (String, int, long, double, boolean, List<T>, or a nested class), and emits one class per object with the root named Root. Conversion runs live as you type.

Good to know

JSON to Java turns a JSON sample into ready-to-use Java class definitions, complete with private fields, getters, and setters. It is aimed at Java and Android developers who need to model an API response or a config payload as plain old Java objects (POJOs) without hand-typing every field. The root object becomes a class named Root, and each nested object becomes its own class named after the field it lives in.

Reach for it when you are wiring up a client against a REST API and want a quick scaffold to deserialize JSON with libraries like Jackson or Gson. Instead of guessing types, you paste one representative response and get a typed skeleton you can drop into your project and refine. It is also handy for one-off scripts, code reviews where you want to visualize a payload's shape, or teaching the structure of nested data.

Read the output as a starting template, not a finished model. Pay attention to how numbers are mapped: a whole number that fits 32 bits becomes int, a larger whole number becomes long, and anything with a decimal becomes double. Inside arrays these switch to the boxed wrappers (Integer, Long, Double) so they fit in a List. When the same key appears across multiple objects in an array, all keys are merged into one class so you do not lose fields that only some elements carry.

One caveat: type inference is only as good as your sample. A field that is null in your input falls back to Object, and a value that looks like a small integer in the sample may actually need long in production, so feed it data that covers the real ranges and optional fields. Because everything runs locally in your browser, you can safely paste internal or sensitive payloads without anything being uploaded.

Frequently asked questions

How are number types chosen?
Integer values that fit in a 32-bit int become int; larger whole numbers become long; any value with a decimal point becomes double. Inside arrays, the boxed wrappers (Integer, Long, Double) are used so they work with List.
How are nested objects and arrays handled?
Each nested object becomes its own class named after the field (PascalCase), and arrays become Listwhere T is the inferred element type. Objects inside an array are merged into a single class so all keys across elements are captured.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

Does JSON to Java generate Jackson or Gson annotations?
No. It emits plain Java classes with private fields and standard getters and setters, but no @JsonProperty, @SerializedName, or other library-specific annotations. You add those yourself, which is useful when your JSON keys differ from valid Java field names.
What Java name does the top-level class get?
The root object is always named Root. Nested objects are named after the field that holds them, converted to PascalCase (for example an address field becomes an Address class).
How does it handle JSON keys that aren't valid Java identifiers?
Keys are split on non-alphanumeric characters and rejoined in camelCase for fields and PascalCase for class names. A name that would start with a digit is prefixed (with an underscore for fields) so the result is a legal Java identifier.
What happens if my JSON is an array at the top level?
It wraps the array in a Root class with a single items field typed as List of the inferred element type, then generates any element classes needed. If the array elements are objects, their keys are merged into one shared class.
Why did a field come out as Object instead of a real type?
That usually means the value was null in your sample or the tool could not agree on a single type across an array's elements. Provide a sample with a non-null, representative value so a concrete type can be inferred.
Can it produce Java records instead of classic classes?
No. The output is traditional classes with mutable fields plus getter and setter methods. If you want records, you would convert the generated classes manually or use a different generator.
Is JSON to Java safe for confidential API responses?
Yes in terms of data handling, because conversion runs entirely client-side in your browser and the input never leaves your device. It also works offline once the page has loaded.
How are boolean fields exposed in the generated code?
Boolean fields use an is-prefixed accessor (for example isActive) rather than getActive, following common Java conventions, while the setter uses the standard set prefix.

Related tools