Generation and Code Structures

JSON → Java

Infer Java classes from JSON and choose fields only or getters and setters as well.

JSON Input

Generated Code

Convert JSON structure to Java classes with merged array fields, nested types, and the imports you need.

JSON and generated Java source are processed only in the current browser. They are not uploaded, executed, or automatically saved.

About This Tool

JSON → Java produces structural Java code for further development without adding a JSON mapping framework by default. Nested objects become classes, arrays become Lists, and integer and decimal types are inferred across all samples.

How to Use It

  1. Paste a JSON object, array, or other valid root value.
  2. Set the root class name and choose fields only or getters and setters.
  3. Click Convert and review Long, Double, nullable references, and nested classes.
  4. Copy the source or download a .java file matching the public root class name.

Examples

  • [{"value":1},{"value":2.5}]: value becomes Double instead of being fixed to the first sample’s integer type.
  • {"matrix":[[1,2],[3,4]]}: generate List<List<Long>> and import List when needed.
  • {"first-name":"Tom","class":"A"}: generate valid field names and preserve original JSON keys in safe comments.

Type Mapping Rules

Integers use Long, decimals or mixed numeric samples use Double, strings use String, and booleans use Boolean. Null-only or incompatible mixed types use Object; empty arrays use List<Object>. Missing or nullable fields use reference types. Only necessary imports are included. Nested types and fields are deduplicated, avoiding reserved words and built-in type names. Rename comments record the original key but do not configure JSON deserialization. Jackson and Gson are not required. Input and output are each limited to 1 MiB, with up to 64 nesting levels, 100,000 nodes, 5,000 merged fields, and 256 types. Unsafe integers, nonfinite numbers, and numbers that underflow to zero produce an error. Other decimals use the browser’s floating-point precision.

Common Uses

  • Quickly draft Java data-transfer classes.
  • Organize object arrays into nested classes and Lists.
  • Review numeric type changes across samples.

Privacy

JSON and generated Java source are processed only in the current browser. They are not uploaded, executed, or automatically saved.

If you need to keep the results, copy or download them before leaving the page.

FAQ

How are JSON numbers mapped?

Integers generally use Long; decimals or mixed integer/decimal samples use Double. Incompatible mixed data may fall back to Object.

Do I have to install Jackson?

No. The default output uses only the Java standard library and does not require third-party annotations.

Will renamed fields map to the original JSON automatically?

No. Comments retain the original keys for reference. Configure deserialization mappings in your chosen framework or application code.

How are null and optional fields represented?

Nullable reference types are used. Your application must handle any further runtime distinction between missing fields and explicit null.

Can I download and compile the code directly?

The filename matches the root class, and the output includes required imports and nested types. Still compile and review it against your target Java version and project conventions.

Back to Developer Tools