JSON to Java Class

Infer Java classes from JSON.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

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

1
Step 1
Paste a sample JSON object.
2
Step 2
Press Run.
3
Step 3
Copy the class, add imports for List and Map, and generate accessors in your IDE.

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?
Paste a sample object and press Run to get a class with typed private fields.
Does it generate getters and setters?
No. Generate them in your IDE or use Lombok.
Why is a long ID typed int?
Types come from the sample value. Change it to long if it can exceed 2,147,483,647.
How are nested objects represented?
As Map<String, Object>.

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 YouTube
  • Inspect Network Activity - Chrome DevTools 101

    Chrome for Developers

    Debugging payloads you paste into JSON and JWT tools.

    Watch on YouTube