JSONGenerator
GeneratorSchemaConvertersExamplesDocs

JSONGenerator

Free online tools for generating random JSON data and JSON Schemas.

Quick Links

  • JSON Generator
  • JSON Schema Converter
  • Examples
  • Docs
  • Blog
  • About
  • Contact
  • Privacy Policy

Converters

  • JSON to YAML
  • YAML to JSON
  • XML to JSON
  • JSON to XML
  • JSON to TOML
  • TOML to JSON
  • JSON to CSV
  • CSV to JSON
  • JSON to Excel
  • Excel to JSON
  • JSON to HTML table
  • JSON to TypeScript
  • JSON to C#
  • JSON to Go
  • JSON to Java
  • JSON to SQL

Support

Having issues? Contact us.

© 2026 JSON Generator. All rights reserved.

JSON to Java Class Converter

Paste JSON and get Java POJO classes with getters and setters as you type.

JSON Input

Paste JSON, upload a .json file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "order_id": 1048576,
  "status": "shipped",
  "total": 129.95,
  "paid": true,
  "created_at": "2025-03-14T09:26:53Z",
  "ship_date": "2025-03-16",
  "coupon": null,
  "customer": {
    "id": 42,
    "full_name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "items": [
    { "sku": "KB-100", "quantity": 1, "unit_price": 89.95 },
    { "sku": "MS-220", "quantity": 2, "unit_price": 20 }
  ],
  "tags": ["priority", "gift"]
}

Java Output

One file that compiles as is. Copy it or download it as a .java file named after the root class.

1

Converting…

Convert JSON to Java classes online

This free JSON to Java converter reads a JSON sample and writes the Java classes that model it. Paste an API response or a config file and you get a root class for the top-level object, a separate class for every nested object, and private fields with getters and setters. It is a quick way to generate a POJO (plain old Java object) without typing out a dozen fields by hand, and the result is ready to use with Jackson.

Everything runs in your browser. Your JSON is not uploaded, there is no sign-up, and the output updates as you type. Set the root class name and the package, or switch on Lombok if you would rather have a @Data annotation than a wall of accessors.

How to convert JSON to a Java class

  1. Paste your JSON into the JSON Input editor, or click the upload button to open a .json file. You can also drag a file onto the editor.
  2. The Java Output updates as you type. If the JSON is invalid, the status bar shows the parser's error so you can fix it.
  3. Type a Class name for the root object and a Package to match your project, or tick Lombok @Data.
  4. Click Copy to put the code on your clipboard, or Download to save it as a .java file named after the root class, such as User.java. Drop it into your project and it compiles.

JSON to Java class example

This small user object, converted with the class name User, produces a User class with the nested address as a public static class inside it, all in one file. Notice that first_name became firstName, the timestamp became OffsetDateTime and the price a double.

JSON input
{
  "id": 1,
  "first_name": "Ada",
  "price": 19.99,
  "created_at": "2025-03-14T09:26:53Z",
  "address": {
    "city": "Oslo"
  },
  "tags": ["a"]
}
Java output
package com.example.model;

import java.time.OffsetDateTime;
import java.util.List;

public class User {
    private long id;
    private String firstName;
    private double price;
    private OffsetDateTime createdAt;
    private Address address;
    private List<String> tags;

    public long getID() { return id; }
    public void setID(long value) { this.id = value; }

    public String getFirstName() { return firstName; }
    public void setFirstName(String value) { this.firstName = value; }

    public double getPrice() { return price; }
    public void setPrice(double value) { this.price = value; }

    public OffsetDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(OffsetDateTime value) { this.createdAt = value; }

    public Address getAddress() { return address; }
    public void setAddress(Address value) { this.address = value; }

    public List<String> getTags() { return tags; }
    public void setTags(List<String> value) { this.tags = value; }

    public static class Address {
        private String city;

        public String getCity() { return city; }
        public void setCity(String value) { this.city = value; }
    }
}
With Lombok
package com.example.model;

import java.time.OffsetDateTime;
import java.util.List;

@lombok.Data
public class User {
    private long id;
    private String firstName;
    private double price;
    private OffsetDateTime createdAt;
    private Address address;
    private List<String> tags;

    @lombok.Data
    public static class Address {
        private String city;
    }
}

How JSON maps to Java types

JSON values and the Java types generated for them
JSONJava typeNotes
{ } objectA classNested objects become static nested classes of the root class, named after the key.
[ ]List<T>T comes from the items. An empty array becomes List<Object>.
stringStringUnless it matches one of the three formats below.
ISO date-time stringOffsetDateTimeFor example 2025-03-14T09:26:53Z.
ISO date stringLocalDateFor example 2025-03-16.
UUID stringUUIDThe java.util.UUID class.
whole numberlongNever int.
decimal numberdoubleAlso used for whole numbers too big for a long.
true / falsebooleanThe getter is named getPaid(), not isPaid().
nullObjectA null is the only sample, so the real type is unknown.

Why long and double?

A sample shows one value, not the range a field can take, so the converter picks the safe type: whole numbers are long and decimals are double. If an array holds both 1 and 2.5, the field becomes List<Double>. Change a long to int by hand when you know the values stay small. For prices, consider BigDecimal instead of double to avoid rounding errors.

Null values, missing fields and boxed types

A long cannot be null, so if a field is null or absent in some objects of an array, the converter uses the boxed type, such as Long, for it. A field whose only value in your sample is null becomes Object. Replace it with the real type once you know it, or paste a sample where the field has a value.

Field names and @JsonProperty

Field names are written in camelCase, so first-name and first_name both become firstName. Keys that are Java keywords or start with a digit are renamed as well: class becomes rootClass and 1st becomes the1St. The generated code does not carry the original key, so a default Jackson mapper will not find first_name in the JSON. Either set a naming strategy on the mapper, as in the next section, or annotate the field with @JsonProperty, which is the way to handle a key that does not follow a pattern.

Java
// JSON key: "class"
@JsonProperty("class")
private String rootClass;

Parse the JSON with Jackson

To turn a JSON string into a Java object at runtime, you need a mapper. The classes are plain JavaBeans, so Jackson's ObjectMapper can read and write them with no annotations. Register JavaTimeModule from jackson-datatype-jsr310 for the date types, and use PropertyNamingStrategies.SNAKE_CASE (Jackson 2.12 or newer) when your JSON keys are in snake_case. For a top-level array, pass new TypeReference<List<User>>() {} to readValue. Both readValue and writeValueAsString throw a checked JsonProcessingException.

Jackson
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

ObjectMapper mapper = new ObjectMapper()
    .registerModule(new JavaTimeModule())                       // OffsetDateTime, LocalDate
    .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); // first_name -> firstName

User user = mapper.readValue(json, User.class);
String backToJson = mapper.writeValueAsString(user);

Identical shapes share one class

When two objects have exactly the same keys and types, for example billing and shipping addresses, the converter generates a single class and uses it for both fields. That keeps the output short, but the class name comes from one of the keys. Rename it to something neutral like Address in your editor. For an array at the top level, the converter models one element and names that class with your root class name.

POJOs, Lombok and records

The default output is a mutable POJO: private fields plus a getter and setter for each one, which every Java framework understands. Tick Lombok @Data to leave out the accessors and let Lombok generate them, along with equals, hashCode and toString; the project then needs the Lombok dependency. Since Java 16 you can also use records for immutable data. The converter does not write records, but the conversion is mechanical: the fields become the record components, and Jackson 2.12 and later reads and writes records.

The same classes as records
public record User(long id, String firstName, double price,
                   OffsetDateTime createdAt, Address address, List<String> tags) {

    public record Address(String city) {}
}

One file that compiles

Java allows only one public top-level class per file, and the file must be named after it. So the root class is the only top-level class in the output, and every other class, along with any enum the converter generates for a field with a few repeated string values, is nested inside it as a public static member. The package line and the imports sit once at the top. Save the output as User.java (the Download button already uses the root class name) and it compiles with no editing.

In other code, refer to a nested class through the root, as User.Address, or import it with import com.example.model.User.Address;. Jackson reads static nested classes the same way as top-level ones. If you prefer one file per class, move a nested class out, drop the static keyword and give it its own file. If the root class name clashes with a java.lang type such as String, the converter renames it, for example to PurpleString, and the download follows the new name.

Why convert JSON to a Java object?

  • Calling REST APIs: Model a response once and let Jackson, RestTemplate or WebClient deserialize it into typed objects instead of Map<String, Object>.
  • Spring Boot request and response bodies: Generate the DTO classes for a controller from an example payload in the API docs.
  • Reading config and data files: Turn a JSON settings or fixture file into a class so the rest of the code works with typed fields.
  • Test data and mocks: Build classes for the sample documents you use in unit tests and contract tests.

Need example data to try this with? Create it with the JSON Generator. To describe the same data as a contract, use the JSON Schema Generator, and if you also work in other languages, there are converters for JSON to TypeScript, JSON to C# classes and JSON to Go structs. When a typed schema matters more than the text format, our comparison of Protobuf vs JSON is worth a read.

Frequently Asked Questions

How do I convert JSON to a Java class?

Paste your JSON into the JSON Input editor, or upload a .json file. The Java classes appear in the output editor as you type. Set the root class name and package, then copy the code or download it. The download is a single .java file named after the root class, such as User.java, and it compiles as it is.

Does the generated Java code compile as one file?

Yes. The root class is the only top-level public class, and every other class is a public static nested class inside it, so the whole output compiles as one file named after the root class. Refer to a nested class as User.Address, or import it.

What is a POJO and how do I get one from JSON?

A POJO (plain old Java object) is an ordinary class with private fields and getters and setters, with no framework base class. This converter generates exactly that from a JSON sample: one class for the root object and one for every nested object.

Does the converter use int or long for JSON numbers?

Whole numbers become long, never int, because a sample cannot tell you how large a value may get. Numbers with a decimal part become double. A field that is null or missing in some objects of an array becomes the boxed type, such as Long.

How are dates and times handled?

Strings in ISO 8601 date-time form, such as 2025-03-14T09:26:53Z, become OffsetDateTime, and plain dates such as 2025-03-16 become LocalDate. UUID strings become java.util.UUID. Any other format stays a String. With Jackson, add the jackson-datatype-jsr310 module to read the java.time types.

What if my JSON keys are snake_case or are not valid Java names?

Field names are converted to camelCase, so order_id becomes orderID and keys that are Java keywords or start with a digit get a safe name. The original key is not kept in the output. Set Jackson's SNAKE_CASE naming strategy to map snake_case keys back, or add @JsonProperty to individual fields.

Can I generate Lombok classes or Java records?

Tick Lombok @Data to replace the getters and setters with a single @lombok.Data annotation on each class. The tool does not generate records, but a generated class is easy to turn into one: use the field names and types as the record components.

Is my JSON uploaded to a server?

No. The classes are generated entirely in your browser with JavaScript, so your JSON never leaves your device. That makes it safe to use with real API responses and internal data.

Related converters

  • JSON to TypeScript ConverterGenerate TypeScript interfaces or types from a JSON sample.
  • JSON to C# Class ConverterGenerate C# classes with properties for System.Text.Json or Newtonsoft.Json from JSON.
  • JSON to Go Struct ConverterGenerate Go structs with json tags from a JSON sample.
  • JSON to SQL ConverterGenerate a CREATE TABLE statement and INSERT rows from a JSON array.
  • JSON to YAML ConverterConvert JSON to clean, readable YAML for config files, Kubernetes and CI pipelines.
  • YAML to JSON ConverterConvert YAML, including anchors and multi-document files, to formatted JSON.

See all JSON converters