Skip to content

JSON to Java Classes Transformer

Generates Java classes from JSON: the page runs json_typegen (WebAssembly) in Kotlin mode and rewrites each data class into a Java class with private fields, an all-args constructor, getters and setters.

Creating a POJO to deserialize a REST response with Jackson.

When to use it

  • Creating a POJO to deserialize a REST response with Jackson.
  • Sketching DTO classes for a Spring controller from an example payload.

How to use

  1. Paste a JSON object or array into the left editor.
  2. Read the classes: the root is Root and nested objects become separate classes named after their key.
  3. Copy them into separate .java files (imports for List and Jackson are included) and adjust types if needed.

JSON

{
  "id": 42,
  "user_name": "ada",
  "active": true,
  "tags": ["admin", "editor"]
}

Java classes

import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Root {
	private Long id;
	@JsonProperty("user_name")
	private String userName;
	private Boolean active;
	private List<String> tags;

	public Root(Long id, String userName, Boolean active, List<String> tags) {
		this.id = id;
		this.userName = userName;
		this.active = active;
		this.tags = tags;
	}

	public Long getId() {
		return this.id;
	}

…

Details and limitations

Generation runs in the browser with WebAssembly; there are no settings.

snake_case keys become camelCase fields with Jackson @JsonProperty; the Jackson import and java.util.List are imported when used.

Numbers map to Long or Double and booleans to Boolean; boolean getters use get, not is.

A null value is typed as Object, and an array of nulls as List<?>. Replace them with concrete types once you know the real data.

FAQ

Can I convert a JSON array at the root?

Yes. The root becomes a wrapper class Root with a List<Root2> field, and the array elements become class Root2.

Are optional fields handled?

Keys missing from some array elements are detected, but the Java output drops the optional marker, so every field is a plain nullable wrapper type.

Does it generate Lombok annotations or records?

No. It writes plain classes with explicit constructors, getters and setters.

How are null values typed?

A field that is null in the sample becomes Object (private Object note;), because no concrete type can be inferred. Provide a sample with a real value to get String, Long or a nested class.

Specifications and references