How to convert JSON to Java
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Java code into your project.
What you get
- Immutable Java records (Java 16+), one per object.
@JsonPropertyfrom Jackson only where the field name differs from the JSON key.- Primitive types for required numbers and booleans, boxed types (
Long,Boolean) when a value can be missing or null.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
How do I deserialize the JSON?
With Jackson 2.12 or later: new ObjectMapper().readValue(json, Root.class). Records are supported out of the box.
Why is only the first record public?
A Java file can contain only one public top-level type, named like the file. Save the output as Root.java, or move each record into its own file and make it public.
Can I get classes with getters and setters instead?
Records are the modern, concise choice. If you are on Java 8 or 11, convert each record into a class with private fields and getters, or use Lombok @Data.