JSON to Java
Generate Java types from a JSON sample. Pick modern record declarations or classic POJOs with getters and setters. Keys that are not valid camelCase Java names get a @JsonProperty annotation so Jackson still binds them.
How to generate Java classes from JSON
- Paste a JSON sample — ideally an array of several records, so optional fields are detected.
- Set the Root type name. Nested objects are named after the key that holds them, singularised for arrays.
- Choose record for immutable data carriers, or class if you need a mutable bean — some frameworks still require a no-arg constructor and setters.
- Set a Package to get the declaration at the top of the file.
- Copy the code, or download it as a file.
Type mapping
- Required integers →
long; optional ones →Long, because a primitive cannot be null. - Fractional numbers →
double/Double. - Booleans →
boolean/Boolean. In class mode, the getter for a required boolean isisX(), matching the JavaBeans convention. - Arrays →
List<T>with the element type boxed. - null / mixed →
Object.
Nested types are emitted as public static members of the root type, so the whole model fits
in one file. Split them out if you prefer one type per file.
Getting good types out of a sample
Type inference from a sample is only as good as the sample. Three habits make the output far more useful:
- Paste an array, not one record. When you pass several records, a key missing from any of them is marked optional and a field that is sometimes a number and sometimes a float widens to a float. One record makes everything look required.
- Include the awkward cases. A record with a null, an empty array, and a missing optional key teaches the generator more than ten identical happy-path records.
- Check unions by hand. A field that holds different shapes in different records falls back to the language's "any" type. That is a signal your data has a variant the generator cannot express — model it explicitly.
Privacy
Nothing is uploaded. Inference and code generation run in this tab. No server sees the payload you paste — which matters, because real API responses tend to contain real user data.
FAQ
Records or classes?
Records for anything you deserialise and read — less code, immutable, correct equals and hashCode for free. Jackson supports them natively since 2.12. Classes if a framework needs bean semantics, or you target Java 11 or older.
Which Jackson version do the annotations need?
@JsonProperty has been in com.fasterxml.jackson.annotation since Jackson 2.0. For records, use 2.12 or later so the canonical constructor is discovered without extra configuration.
What about BigDecimal for money?
Nothing in a JSON sample distinguishes a price from any other number, so you get double. Change money fields to BigDecimal by hand — floating point and currency do not mix.