JSON to Java Class
Infer Java classes from JSON.
About this tool
Paste a JSON object and get a Java class with one private field per key. Types are String, int, double, boolean, List<T> and Map<String, Object>. Getters, setters and imports are not generated.
How to use
How it works
Strings map to String, whole numbers to int, decimals to double, booleans to boolean, arrays to List<T> (items merged, boxed types such as Double) and nested objects to Map<String, Object>. The class is named Root and all fields are private.
Worked example
A scored item
- Input
- {"id":1,"name":"Ada","score":9.5,"tags":["a"],"active":true}
- Output
- import java.util.List; import java.util.Map; public class Root { private int id; private String name; private double score; private List<String> tags; private boolean active; }
- Walkthrough
- The java.util imports are included. Use your IDE or Lombok for getters and setters.
Limitations
- No getters, setters, constructors or Jackson/Gson annotations.
- Imports for java.util.List and java.util.Map are added; list items use boxed types such as List<Double>.
- Whole numbers are always typed int, even if the real field can be larger; change it to long when needed.
- Nested objects become Map<String, Object>, not nested classes.
Questions
How do I convert JSON to a Java class?
Does it generate getters and setters?
Why is a long ID typed int?
How are nested objects represented?
Features
- Typed private fields
- List<T> from arrays
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
What Is A RESTful API?
Traversy Media
Most APIs exchange JSON—context for pretty-print and schema checks.
Watch on YouTubeInspect Network Activity - Chrome DevTools 101
Chrome for Developers
Debugging payloads you paste into JSON and JWT tools.
Watch on YouTube
- web.dev
Google
Modern web guidance that pairs with encoding and tooling pages.
- Introduction to JSON Web Tokens
jwt.io
JWT structure for decoder and debugger pages.