JustRandom

JSON to Java Class Converter

Generate Java classes, records, and accessors from JSON.

Generate Java from JSON

Paste sample JSON and generate Java models locally in your browser.

Use an object or an array of objects for model inference.

Java options

Generated code

Generated code will appear here.

Convert JSON to Java

Generate Java POJOs or records from sample JSON with typed fields and named nested models. Arrays become List<T>, and an import is added when the inferred model uses a list.

POJO output can include no-argument and all-argument constructors plus getters and setters. Record output provides a compact immutable data carrier for projects using a compatible Java version.

Java POJO, record, and package options

An optional package declaration can be placed above the generated models. Package names are validated as dot-separated Java identifiers before generation.

Primitive numeric and boolean types are used for required non-null fields. When a sample shows a field as nullable or missing, wrapper types such as Integer, Double, and Boolean allow the generated model to represent that state.

Java conversion example

Example JSON input:

{
  "order_id": 101,
  "customer": {
    "display_name": "Ada"
  },
  "items": ["book", "pen"]
}

Generated Java output:

import java.util.List;

public record RootModel(
    int orderId,
    RootModelCustomer customer,
    List<String> items
) {}

public record RootModelCustomer(
    String displayName
) {}

How to generate Java code

  1. Paste a JSON object or an array of similar objects.
  2. Enter the root Java class or record name.
  3. Choose POJO or record output and adjust the package, constructor, accessor, and field-name options.
  4. Generate the Java source, then copy it or download the .java file.

Frequently asked questions

How does JSON become a Java class?

The converter infers Java field types from the sample, creates a root class, and adds separate named classes for nested objects.

What is the difference between POJO and record output?

POJO output uses fields and can generate constructors, getters, and setters. Record output uses Java record components for a concise immutable data carrier.

How are nullable numbers represented?

Required non-null numbers use int or double. Nullable or optional numbers use wrapper types such as Integer or Double so null can be represented.

How are nested classes generated?

Nested JSON objects become additional named Java models referenced by the parent field. Arrays of nested objects use List with the generated model type.

Can it generate getters and setters?

Yes. POJO output can generate a getter and setter for every inferred field. Records do not use that option because their components already expose accessors.

Private browser-based conversion

Your JSON input, field names, root model name, and generated Java source stay in this browser. They are not sent to a backend, added to the URL, or saved in local storage or cookies.

Related tools

Compare another language-specific converter that uses the same local JSON inference engine.

Back to JSON to Code overview