Type generation

JSON to Javamodels for Java and Kotlin

Compare both records. An input array produces the element model; use List<Root> when decoding the array.

JSON to Java

JSON input

Parsed and generated in this browser. Input is not uploaded or stored.

Generated source

Generation options

Jackson 2.x; Kotlin requires its Kotlin module. Samples infer types, not validation. Review decoder settings below.

Array input: this file defines the element model. Decode List<Root>.

2 classes · 2 nullable fields

JSON to Java helps when an API response is your only starting point. Supply several representative objects to expose properties absent from the first record and nulls that need a wider type.

This JSON to POJO converter creates a draft, not an API contract. Review business requirements separately; samples cannot establish which future values are valid.

Why use JSON to Java?

Merge every record

JSON to Java merges fields across every object at the same array position. A property appearing later is retained, and missing or null evidence changes its nullable type.

Two sample cards merge into one model, with a hollow marker for a field missing from one record.

Map keys without losing their spelling

A Java class generator needs legal identifiers. Jackson annotations connect renamed properties to their original JSON keys, including punctuation, Unicode and stable collision suffixes.

Irregular key shapes connect through matching colored links to safe model fields and a nested class.

Review the evidence before generating

01

Include meaningful differences

Use one object or a nonempty array containing only objects. Arrays merge element models; they do not generate a wrapper with an invented property. Nested arrays are inferred recursively.

02

Choose nullable and nesting behavior

Observed mode widens fields seen missing or null. All mode boxes Java primitives and makes Kotlin properties nullable with null defaults. Disable nesting to emit top-level helper classes in the same file.

03

Export the current revision

Automatic generation waits 350 ms. Turn it off for the Generate button or Ctrl/Cmd+Enter. Editing immediately disables exports. Clear and Example retain one undo snapshot of input, settings and output.

Fields, types and source files

Exact numeric types

Plain integers fitting signed 64 bits become long/Long. Larger integers use BigInteger; decimals and exponent tokens use BigDecimal, including 1.0 and 1e3. No numeric token passes through JavaScript floating point.

Kotlin constructor parameters

Select JSON to Kotlin data class output on this page. Observed nullable fields use T? = null; non-null fields have no default. Empty objects at the root produce an ordinary class because a data class requires parameters.

Names and annotations

Names become ASCII camelCase with deterministic suffixes. Java fields receive JsonProperty; Kotlin parameters and getters each receive it. Fully qualified types avoid collisions with root names such as String or List.

A single source file

Java uses public fields and static nested classes by default. Kotlin uses nested data classes. Turning nesting off emits nonpublic Java helper classes or top-level Kotlin classes, still in one downloadable file.

Compatibility and limits

Jackson integration is required
Annotated output targets Jackson 2.x. Kotlin also needs jackson-module-kotlin and kotlin-reflect. Enable FAIL_ON_NULL_FOR_PRIMITIVES and StrictNullChecks for null checks; these models alone do not validate input. Java references remain nullable even in observed mode.
Unknown types require a decoder policy
Mixed values and null-only fields become Object/Any; empty arrays have unknown elements, and empty nested objects use Map. Enable USE_BIG_INTEGER_FOR_INTS and USE_BIG_DECIMAL_FOR_FLOATS for exact numbers in these positions. Empty root classes need FAIL_ON_EMPTY_BEANS disabled when serialized.
Some mappings are deliberately rejected
Empty JSON keys cannot be represented by JsonProperty because an empty annotation name means the default name. Disabling annotations rejects any field that requires renaming. Use a map or custom decoder for unsupported mappings.
Samples are not schemas
No JSON Schema, OpenAPI, Lombok, records, Gson, date or enum inference is provided. Strings remain strings. Root scalars, empty arrays and mixed root arrays fail. Absent and explicit null are not tracked as separate states.
Finite input and output budgets
Strict JSON only: no comments, duplicate keys, repair, URL fetch or file import. Limits: 500,000 characters, 50,000 nodes, depth 40, 100 fields per object, 200 classes, 1,000 characters per key/number token, exponent magnitude 10,000 and 1,000,000 output characters.

JSON to Java questions

How are numbers typed?

JSON to Java uses signed 64-bit types for plain in-range integers, BigInteger for larger ones and BigDecimal for decimal or exponent spelling. Mixed Object/Any positions require the decoder precision settings described above.

When does it add JsonProperty?

With annotations enabled, every Java field and each Kotlin constructor parameter/getter carries the original key. This also resolves renamed reserved words and collisions. Empty keys still need a different model.

Why did a field become Object?

The samples contain incompatible types or only null at that position. A broad type expresses that lack of evidence. Add representative values or refine the generated class after confirming the API contract.

Can I generate a Java class from an API response?

Yes. Paste an object or an array of object samples, choose the root name and review the inferred fields. For an array, decode List<Root> rather than Root. The browser generates source but does not compile it.

Are nested objects saved as separate Java files?

No. The default places static helper classes inside the root. Disabling nesting places nonpublic helper classes in the same file. Copy or download the complete source; add a package declaration in your own project.

Found an inference case to improve?

Test your generated model

Use JSON to Java with representative records, review nullability and Jackson settings, then compile and test the exported model in your project.