Java to JSON Schema

Paste a Java class or record and produce JSON Schema draft 2020-12.

Formats Java → JSON SchemaSteps & examples
A drafting square connects a record blueprint with branching fields.

Workspace

Runs locally in your browser. No file upload.

Input & settings

Paste text or edit a loaded file
Sample Java and generated JSON Schema

Try sample loads this Java input locally. Click Generate JSON Schema to reproduce the result.

Download Java input · Download generated JSON Schema

Java input:

public record Person(String name, int age, boolean active) {}

Actual output:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Person",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer"
    },
    "active": {
      "type": "boolean"
    }
  },
  "additionalProperties": false,
  "required": [
    "name",
    "age",
    "active"
  ]
}

Unsupported example: if a class extends a base class, inherited fields are omitted. Add them manually. The tool also marks every record component required, even Optional; class fields are not marked required. Custom-type references need matching definitions.

Select a file or paste data to begin.

Result

Copy or download when available

Sketch a JSON Schema from Java fields

  1. Paste a basic Java class or record declaration.
  2. Generate the JSON Schema draft 2020-12 output.
  3. Review property types and resolve custom-type references before using the schema.

Worked example

A Java record with String name and int age produces schema properties with string and integer types. Review required fields separately against your API’s actual contract.

Input and output

Start with one simple class or record declaration. Read the generated properties alongside the Java source and validate a representative JSON document with your own schema validator. A date-like Java type may be represented as a string without encoding every rule your application applies to dates.

Format and size limits

Only declarations recognized by the parser contribute fields. A custom type may become a reference whose definition you must supply. Read the required list carefully for records, especially when a component is Optional or when your serializer omits null values.

If processing fails

If an expected property is missing, check whether it comes from a superclass, a getter or a serialization annotation. Compare the schema with an actual serialized instance. Add the missing properties and definitions before relying on validation in your project.

Questions about this tool

Are validation annotations and inheritance included?

No. This is a lightweight parser, not a Java compiler. Advanced generics, inherited fields and annotation-driven validation need manual review.

What happens to custom Java types?

Unknown custom types become references. Supply their schemas or adjust those references before using the output for validation.

How it works

Handles common Java primitives, arrays, List, Set, Optional and records. Unknown custom types are expressed as references.

Important limitations

This is not a Java compiler: inheritance, annotation-based constraints and sophisticated generics are not supported. Custom types become references without generated definitions. Every parsed record component is marked required, including Optional; class fields are not marked required. Review the schema before use.