JSON Schema Generator

Generates a JSON Schema from a sample document, inferring types and structure. A first draft for validating API payloads, config files and form submissions — which then needs the constraints only you know.

Live demo · real result from this tool
Draft

schema.json

{  "$schema": "https://json-schema.org/draft/2020-12/schema",  "title": "User",  "type": "object",  "properties": {    "id": {      "type": "string",      "format": "uuid"    },    "email": {      "type": "string",      "format": "email"    },    "age": {      "type": "integer"    },    "active": {      "type": "boolean"    },    "created": {      "type": "string",
      "format": "date-time"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "zip": {
          "type": "string"
        }
      },
      "required": [
        "city",
        "zip"
      ]
    },
    "orders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sku": {
            "type": "string"
          },
          "qty": {
            "type": "integer"
          },
          "price": {
            "type": "number"
          },
          "gift": {
            "type": "boolean"
          }
        },
        "required": [
          "sku",
          "qty",
          "price"
        ]
      }
    }
  },
  "required": [
    "id",
    "email",
    "age",
    "active",
    "created",
    "tags",
    "address",
    "orders"
  ]
}

Inferred from one sample: add enums, ranges (minimum/maximum), lengths and patterns yourself, and remove fields from required that are genuinely optional.

Processed on your device — nothing is uploaded.

How to use JSON Schema Generator

  1. Paste a representative JSON document.
  2. Copy the generated schema.
  3. Add required fields, enums, ranges and formats — that is where the validation lives.
  4. Decide on additionalProperties deliberately rather than leaving the default.
  5. Inference reads one sample: it cannot tell optional from present-this-time.
  6. Arrays are typed from their elements; an empty array gives no information at all.
  7. Declare $schema so validators apply the right draft’s rules.

What a schema buys you that a type does not

A TypeScript interface disappears at compile time and validates nothing at runtime. A JSON Schema is data, checked while the program runs, so it catches the case that actually breaks things: an upstream service changing its response shape. It is also portable — the same schema validates in JavaScript, Python, Go and Java, documents the API, and can generate types in several languages. One artefact, several jobs.

Inference gets you the shape and none of the rules

From one sample a generator can see that age is a number and email is a string. It cannot know that age must be between 0 and 130, that email needs a format constraint, that status is one of four values rather than any string, or which fields are genuinely optional. Those constraints are where the value is — a schema that only records types catches a field disappearing and nothing else. Treat the output as scaffolding and add required, enum, minimum, maxLength and format by hand.

additionalProperties is the decision to make deliberately

By default a schema permits properties it does not mention, so an object with unexpected extra fields validates happily. Setting additionalProperties: false rejects them, which catches typos in config files and stops unexpected data flowing through your system. The trade is that it breaks forward compatibility: a client validating a server’s response strictly will reject it the day the server adds a field. Strict for config and inbound data you own; permissive for responses from services you do not control.

Choose the draft version and say which it is

JSON Schema has several drafts — Draft 7 is the most widely supported, and 2020-12 is current, with real differences in how $ref, items and tuple validation work. Declare $schema at the top so validators know which rules to apply, and check that your chosen library actually supports that draft. Mismatched assumptions here produce schemas that pass in one validator and fail in another.

Frequently asked questions

Does it infer required fields correctly?
It marks every key present in your sample payload as required by default — remove any keys from the required array afterward that should actually be optional.
Can I use this file directly on my live site?
Yes, as a starting point — double-check paths, URLs, and directives against your actual domain before deploying.
Does this tool call any external API to generate the file?
No. Everything is built client-side in your browser from the values you enter.
How do I mark fields as required?
With a `required` array listing the property names, at the level of the object containing them. A generator cannot infer this from one sample — if you have several documents, the fields present in all of them are your candidates.
What is the difference between JSON Schema and TypeScript types?
TypeScript checks at compile time and vanishes at runtime; JSON Schema is data validated while the program runs, so it catches bad input from outside your code. They complement each other — several tools generate TypeScript types from a schema, which keeps one source of truth.
Should I set additionalProperties to false?
For configuration and data you control, yes — it catches typos and unexpected fields. For responses from a service you do not control, no: strict validation breaks the day they add a field, which they are entitled to do.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close