JSON to Java Class

Paste JSON, get Java classes with the field names already camelCased and Jackson annotations where the key would not be a legal identifier. Nested objects become static inner classes, so one file is enough to copy.

Types come from the values you paste: whole numbers become Integer or Long, decimals Double or BigDecimal, null becomes Object (the tool cannot know what it should be). Empty arrays also fall back to List<Object> for the same reason. Missing keys inside an array are tolerated — a field that only some records carry is still generated once.

About JSON to Java Class

Paste JSON, get Java classes that compile: field names camelCased, nested objects as static inner classes, and a @JsonProperty added wherever the key would not be a legal identifier.

The usual failure mode of this kind of tool is code that looks right and deserialises to all nulls. It almost always comes down to field names: Java identifiers do not allow -, @ or a leading digit, while JSON keys allow anything. So the rule here is strict — whenever the key and the field name differ, a @JsonProperty("original key") is emitted. With "no annotations" selected that mapping is skipped, and if a key is illegal the page says so instead of pretending it worked.

Types are inferred from values, and there are three things it cannot know. null becomes Object — there is no way to tell whether it should have been a string or a nested object. An empty array becomes List<Object> — there are no elements to look at. Integers pick between Integer and Long by range. Switch to the Long / BigDecimal mode when it matters: do not use Double for money, since the old 0.1 + 0.2 problem is a real one when the number is currency.

Nesting is flattened. Every nested type becomes a public static class of the root class rather than a deep chain — Java's static inner classes can refer to siblings, so flattening avoids the scope surprises of classes nested inside classes. The cost is that names must be unique at that level; duplicates get a numeric suffix.

Fields are unioned across array elements. If the first orders entry has items and the second does not, the field is still generated once; the missing one is simply null at runtime. The tool will not invent a default.

Frequently asked questions

Will the generated code compile?

Yes. The Jackson mode needs jackson-databind on the classpath; the Lombok mode needs lombok. Adjust the package and class name as needed.

Why do field names differ from my JSON keys?

Java identifiers forbid hyphens, @, and leading digits, and snake_case is not Java convention either. Names are camelCased and mapped back with @JsonProperty.

Why not generate records?

Records (Java 14+) are immutable and need extra setup for Jackson deserialisation (-parameters). Plain POJOs work everywhere, so that is the default.

Which number mode should I use?

Integer / Double is fine for most data. Use Long / BigDecimal for money, timestamps, and IDs beyond the 32-bit range — Double loses precision on currency.

What if the top level is an array?

Supported. Objects in the array are merged into one class with the union of their fields, named after the root class name you enter.

Is my JSON uploaded?

No. Everything runs in your browser; the server never sees your data.

Related tools

Converters View all ›