JSON to Java classes

Paste JSON and get Java POJOs with Jackson annotations, boxed types and accessors. Runs in your browser; nothing is uploaded.

About this converter

Turning an API response into Java classes is the least interesting part of consuming an API and one of the most tedious, because Java wants a class per nested object, a field per key, and a getter and setter for each. For a response with four nested levels that is a lot of typing before you have written any logic.

This generator produces a POJO per object, with Jackson annotations where they are needed. A key like user_name cannot be a conventional Java field name, so the field becomes userName and carries a JsonProperty annotation preserving the original. Keys that are already valid Java identifiers are left alone and get no annotation, keeping the output readable rather than uniformly cluttered.

Every field uses a boxed type - Long, Double, Boolean rather than long, double, boolean. This is deliberate and it matters. A primitive cannot represent an absent JSON field: a missing integer would silently deserialise to 0, which is indistinguishable from a real zero. A boxed type gives you null, so you can tell "not provided" from "provided as zero".

Whole numbers become Long rather than Integer because JSON numbers from JavaScript and Python backends regularly exceed what an int holds, and discovering that through a runtime overflow is a bad afternoon.

Nested objects become their own classes, named after the key that contained them and singularised where the key was plural. Arrays of objects are merged across every element, so a field missing from some records is visible in the model rather than inferred from whichever record happened to come first.

As with the other generators, this infers from a sample rather than a schema, so review the result - especially nullability. Everything runs in your browser.

Frequently asked questions

Why boxed types instead of primitives?
A primitive cannot express a missing field. A missing number would deserialise to 0, indistinguishable from a real zero. Boxed types give you null instead.
Do I need Jackson for this?
Only if annotations were emitted, which happens when a JSON key is not a valid Java field name. Otherwise the classes are plain POJOs that work with any mapper.
Can it generate records or Lombok annotations instead?
Not currently. The output is deliberately plain so it compiles anywhere without additional dependencies.

Related converters