Just Formatter

JSON Schema Generator

Paste any JSON and generate a valid JSON Schema instantly — nested objects, arrays, optional fields, and null types handled automatically. Choose Draft-07 or Draft 2020-12.

JSON Input

JSON Schema Output

How to Generate a JSON Schema in 3 Steps

1

Paste your JSON

Paste any JSON object or array into the input panel. You can use the Load sample button to try the tool with a pre-built example that includes nested objects, arrays, and null values.

2

Configure your options

Choose Draft-07 or Draft 2020-12, add an optional schema title, toggle whether all fields should be marked as required, and optionally add additionalProperties: false for strict validation.

3

Copy or download the schema

Click Generate Schema to produce the JSON Schema output. Use Copy to paste it directly into your code, or Download .json to save the schema file for use with validators or OpenAPI specs.

What Is JSON Schema?

JSON Schema is a vocabulary for describing the structure and constraints of JSON data. A JSON Schema document is itself a JSON object that defines what properties a value must have, what types each property must be, which properties are required, and additional constraints like minimum values, string patterns, or array lengths.

JSON Schema is used for three main purposes: validation (checking that a JSON value matches the expected structure), documentation (describing an API contract or data model), and code generation (producing TypeScript interfaces, Python dataclasses, Go structs, and other typed models from the schema).

JSON Schema is the type system behind OpenAPI 3.0, which means any schema you generate here can be used directly as an OpenAPI component definition. It is also the validation format supported by MongoDB, AWS EventBridge, and many other data stores and messaging systems.

How the Generator Works

The generator traverses your JSON recursively and maps each value to its JSON Schema equivalent type. Primitives map directly: string, boolean, integer (whole numbers), number (decimals), and null.

For objects, each key becomes a property in the properties map with its inferred schema, and the list of keys is added to required when that option is enabled.

For arrays, the generator collects the schema of every item and merges them into a single unified items schema. When array items are objects with different keys, the merge produces a union of all properties — fields present in every item are marked required; fields present in only some items are optional. When array items have mixed types, the output uses anyOf.

JSON Schema Draft-07 vs Draft 2020-12

FeatureDraft-07Draft 2020-12
$schema URIhttp://json-schema.org/draft-07/schema#https://json-schema.org/draft/2020-12/schema
Validator supportAJV, jsonschema, tv4, Ajv 8+AJV 8+, hyperjump, Ajv 8+ (2020-12 mode)
$ref handlingCan mix $ref with siblingsCleaner $ref, no sibling merging
Tuple arraysitems as arrayprefixItems keyword
Vocabulary systemNot availableSupported via $vocabulary
Best forMaximum compatibilityNew projects needing latest features

For most use cases, choose Draft-07. It has the widest validator support and is the default for OpenAPI 3.0 schemas. Use Draft 2020-12 if you need advanced vocabulary features or are building a new schema registry that supports it.

Generated Schema Example

The following JSON input produces the schema on the right with default options (Draft-07, required enabled).

JSON Input

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "score": 98.5,
  "tags": ["admin"]
}

Generated JSON Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" },
    "active": { "type": "boolean" },
    "score": { "type": "number" },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    }
  },
  "required": ["id", "name", "active", "score", "tags"]
}

Use Cases

API Request Validation

Generate a schema from your expected request body shape and use it to validate incoming API payloads with AJV or Zod — catch missing fields and type errors before they reach your business logic.

OpenAPI / Swagger Components

JSON Schema is the type system behind OpenAPI 3.0. Generate schemas from your data models and paste them directly into the components/schemas section of your OpenAPI spec.

Database Document Contracts

MongoDB, Firestore, and DynamoDB all support JSON Schema for document validation rules. Generate a schema from a sample document and apply it as a collection validator.

Code Generation Input

Tools like json-schema-to-typescript, quicktype, and datamodel-code-generator accept JSON Schema as input to produce TypeScript, Python, Go, and Java types — use this generator as the first step.

Form Validation

Libraries like react-jsonschema-form, ajv-formats, and Angular reactive forms support JSON Schema-driven validation — generate a schema from your form data model to define validation rules declaratively.

Data Pipeline Contracts

Define the shape of messages flowing through Kafka topics, EventBridge buses, or SQS queues. A JSON Schema at the producer enforces the contract that consumers rely on.

Generator Options Explained

Mark fields as required

When enabled (default), every property on each object is added to its required array. For arrays of objects, only properties that appear in every item are marked required — properties present in some items but not others are omitted from required automatically. Disable this option to produce a schema with no required constraints, useful when all fields are optional.

additionalProperties: false

Adds "additionalProperties": false to every object schema. This makes the validator reject any object that contains properties not listed in the schema. Use this for strict API request validation where unexpected fields should cause a validation error. Leave it off for partial schemas where objects may have extra fields.

Schema Title

Adds a "title" field at the root level of the generated schema. This is used by tools like json-schema-to-typescript and openapi-generator to name the generated type or class, and appears in schema documentation and registry UIs.

Limitations

  • Sample-based inference: The schema reflects only the values present in your sample. Fields that are sometimes null or have different types in real data will not be captured unless your sample contains those variations.
  • Null fields produce {"type": "null"}: If a field is null in your sample but can hold a real value, edit the schema manually to use anyOf with both the expected type and null.
  • String formats not detected: Email addresses, URIs, date-time strings, and UUIDs all produce {"type": "string"}. Add format, pattern, or enum constraints manually.
  • No numeric constraints: Minimum, maximum, multipleOf, and similar number constraints are not inferred. Add them manually after generation for data with known valid ranges.

Frequently Asked Questions

How do I generate a JSON Schema from JSON?

Paste your JSON into the input panel, choose your options (schema version, title, required fields), and click Generate Schema. The tool produces a ready-to-use JSON Schema that matches the structure of your JSON.

What is the difference between Draft-07 and Draft 2020-12?

Draft-07 uses $schema: "http://json-schema.org/draft-07/schema#" and is the most widely supported version — compatible with AJV, jsonschema (Python), and most validators. Draft 2020-12 uses the newer "https://json-schema.org/draft/2020-12/schema" dialect and adds improved $ref handling and vocabulary support. Choose Draft-07 unless you specifically need 2020-12 features.

Why are all fields marked as required by default?

The generator marks every field as required because your sample JSON contains all those fields. If some fields are optional in your real data, uncheck "Mark fields as required" or manually edit the required array in the generated schema to remove optional fields.

What does additionalProperties: false do?

Adding additionalProperties: false to an object schema means the validator will reject any JSON object that contains properties not listed in the schema. This makes validation strict — useful for API request payloads where unexpected fields should be rejected.

How are arrays of objects handled?

When the input contains an array of objects, the generator merges all objects in the array to produce a unified item schema. Properties that appear in every object are marked as required (if the option is enabled); properties that appear in only some objects are included in the properties map without a required entry.

What happens to null values?

A JSON field with a null value generates a schema of { "type": "null" }. If the field can be either a value or null in real data, edit the schema to use anyOf: for example, "anyOf": [{"type": "string"}, {"type": "null"}].

Can I use the generated schema with AJV?

Yes. The generated schemas are valid JSON Schema Draft-07 or 2020-12 documents that work directly with AJV. Install AJV, call ajv.compile(schema), and pass your data to the compiled validate function to check it against the schema.

From the Blog

View all →

Related Tools