Skip to content

Menu

JSON to Java

Convert JSON to Java classes

Runs entirely in your browserConvertersFree, no sign-up
Loading tool

01What is JSON to Java?

Hand-writing Java model classes for a JSON payload is tedious and easy to get wrong. Paste a JSON document here and you get plain Java classes (POJOs) that match its shape, ready to use with Jackson or Gson. Types follow the values. Strings become String, decimals double and booleans boolean. Whole numbers become int, or long when a value doesn't fit in a 32-bit int, or BigInteger (with its import) when it is too big even for long. null becomes Object, since the sample tells us nothing about the real type. Arrays turn into List<T>, and Java generics can't hold primitives, so the element type is boxed: [1,2] gives List<Integer>. The java.util.List import is added when a list appears. Empty arrays, and arrays mixing different value types, fall back to List<Object>. All elements of an array are merged before typing. So an array of objects produces one item class with every key seen in any element. Each nested object becomes its own class, named in PascalCase after its key, so a customer field produces a Customer class. Naming is where most generators trip, so the tool does some cleanup. Keys in snake_case, kebab-case or with spaces are turned into camelCase, and order_id becomes orderId. Characters that aren't valid in a Java identifier become underscores. Java keywords, as listed in the Java Language Specification, get a trailing underscore, so class becomes class_. A class name that is already taken, or that would hide a java.lang type or the imported List, gets a number. A key called list therefore produces a class named List2. Two output styles are on offer. Getters/Setters writes private fields with getX and setX methods, using isX for boolean getters as the JavaBeans convention does. Public Fields writes bare public fields. The root class takes its name from the Class name box and comes first, with nested classes after it. For example, {"order_id":"A1","customer":{"name":"Ann"}} with the class name Order gives an Order class with String orderId and Customer customer, plus a Customer class with String name. If the top level is an array of objects, you get the item class and a comment such as // Root is List<Item>. Some limits to keep in mind. Every class is declared public, and Java allows one public top-level class per file, so split them into files or make nested ones static. Renamed fields need @JsonProperty or a naming strategy to map back to the JSON keys. There are no annotations, constructors, equals or toString. Your JSON is converted inside the page and is not uploaded.

Java, Spring Boot and Android developers who need model classes for a JSON payload without typing every field by hand. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON to Java

  1. Enter a root class name in the Class name box. It defaults to Root.
  2. Choose Getters/Setters or Public Fields.
  3. Paste JSON into JSON Input, or load the User Object, API Response or Product example. Parse errors show below the editors.
  4. Read the generated classes in Java Output.
  5. Copy the output and split the classes into separate .java files.

03Worked examples

Input: {"user_id":7,"full-name":"Ann","tags":["a","b"],"meta":null} (Public Fields)
Result: import java.util.List; public class Root { public int userId; public String fullName; public List<String> tags; public Object meta; }
Keys become camelCase and null becomes Object. The tags list adds the java.util.List import.
Input: {"class":1,"items":[{"id":1},{"id":2,"qty":3}]} (Public Fields)
Result: public class Root { public int class_; public List<Items> items; } public class Items { public int id; public int qty; }
class is a Java keyword, so it becomes class_. Keys from every array item merge into one Items class. Import line trimmed.
Input: {"order_id":"A1","customer":{"name":"Ann"},"list":{"x":1}} (Class name Order, Public Fields)
Result: public class Order { public String orderId; public Customer customer; public List2 list; } public class Customer { public String name; } public class List2 { public int x; }
The root class takes the name you typed. A nested object under list gets the class name List2 so it can't hide java.util.List.
Input: [{"id":1},{"id":2,"name":"b"}] (Class name Item, Public Fields)
Result: public class Item { public int id; public String name; } // Root is List<Item>
A top-level array yields the item class plus a comment saying the root is a list. The import line is trimmed here.
Input: {"big":9007199254740993,"ints":[1,2.5]} (Public Fields)
Result: public class Root { public long big; public List<Double> ints; }
A number past the int range becomes long, and a list with a decimal is boxed as Double. Import line trimmed.
Input: {"is_active":true} (Getters/Setters)
Result: public class Root { private boolean isActive; public boolean isIsActive() { return isActive; } public void setIsActive(boolean isActive) { this.isActive = isActive; } }
Boolean getters use the is prefix, so a field already named isActive gets isIsActive(). Rename the field if you want isActive().

04Common use cases

  • Creating DTOs for a Spring Boot REST controller from a sample request body
  • Mapping a third-party API response for use with Jackson or Gson
  • Scaffolding model classes for an Android app that consumes a JSON API
  • Turning an array response into an item class when the endpoint returns a top-level JSON list
  • Checking how a deeply nested payload would look as a class hierarchy before designing the domain model
  • Speeding up a coding exercise or interview task that involves parsing JSON in Java

05Tips

  • Because keys are camelCased, add @JsonProperty("order_id") or set a snake_case naming strategy so Jackson still maps the original JSON keys.
  • Your sample decides int versus long. Switch IDs and epoch-millisecond timestamps to long even if the sample value happens to be small.
  • Fields that were null in the sample become Object, and empty arrays become List<Object>. Replace both with the real types.
  • A key named list, string or object becomes a class with a number on the end (List2, String2) so it doesn't shadow the standard type.
  • On Java 16 or newer, the field list converts neatly into a record if you want immutable DTOs.

06Related concepts

POJO, Jackson, DTO, Getters and setters, Java records.

Frequently Asked Questions

What is JSON to Java?

JSON to Java is a free, browser-based developer tool on AIDToolStack. Convert JSON to Java classes It requires no installation or sign-up and works entirely in your browser.

Is JSON to Java free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON to Java store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe