JSON Schema Generator

Paste JSON to generate a JSON Schema (draft-07) that describes its structure.

Input
Output

How to use the JSON Schema Generator

  1. Paste a JSON example into the left editor. Any valid JSON — an object, array, or primitive — works.
  2. Click "Generate Schema" to produce a JSON Schema in the right panel.
  3. Review the output. Every key becomes a property with its inferred type, nested objects get their own properties block, and all top-level keys are marked required.
  4. Copy the schema into your project. Use it with validators like AJV, API gateways, or documentation tools like Swagger / OpenAPI.
  5. Refine as needed. Add minLength, pattern, enum, or description annotations to tighten the schema beyond what can be inferred from a single sample.

What is JSON Schema?

JSON Schema is a vocabulary that lets you describe the structure and constraints of JSON documents. It is to JSON what XML Schema (XSD) is to XML — a way to say "this field must be a string," "this array must contain objects with these properties," or "this number must be between 1 and 100." The schema itself is written in JSON, which means the same parsers and tools you already use can also read the schema.

The specification has been through several drafts. This tool generates draft-07, which is the most widely supported version across validators (AJV, jsonschema for Python, Newtonsoft.Json.Schema for .NET) and API tools (Swagger / OpenAPI 3.0, AWS API Gateway, Fastify). Draft-07 strikes the best balance between broad tooling support and modern features like if/then/else conditional schemas.

Writing a schema by hand is doable for small objects, but a real-world API response with nested arrays, nullable fields, and mixed types can easily be 200+ lines of schema. This generator reads your sample, walks the structure recursively, infers types, and produces a valid draft-07 schema instantly — giving you a baseline that you can then enrich with constraints and descriptions.

Examples

Simple object

Input:

{
  "name": "Alice",
  "age": 32,
  "active": true
}

Generated schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" },
    "active": { "type": "boolean" }
  },
  "required": ["name", "age", "active"]
}

Nested object with arrays

Input:

{
  "team": "backend",
  "members": [
    {
      "id": 1,
      "name": "Bob",
      "roles": ["admin", "deploy"]
    }
  ]
}

The schema describes members as an array whose items are objects with id (integer), name (string), and roles (array of strings). Each level of nesting gets its own properties block.

API response with mixed types

{
  "status": "ok",
  "count": 3,
  "results": [
    { "id": "abc", "score": 0.95, "metadata": null }
  ],
  "cursor": "eyJwYWdlIjogMn0="
}

The metadata field is inferred as nullable. score is a number (float), count is an integer, and each key is included in the required array since all are present in the sample.

Common use cases

  • Generating an OpenAPI / Swagger schema component from a sample response to bootstrap API documentation.
  • Creating AJV validation rules in Node.js to validate incoming request bodies at runtime.
  • Defining AWS API Gateway request validators that reject malformed payloads before they hit your Lambda.
  • Producing schemas for JSON-based config files to get editor autocompletion and validation in VS Code.
  • Feeding schemas to code generators like quicktype or json-schema-to-typescript to produce typed clients.
  • Validating data pipeline outputs in ETL workflows to catch schema drift before data reaches the warehouse.
  • Setting up contract tests between microservices by committing schemas to a shared repo.

Frequently asked questions

What JSON Schema draft does this use?

The output uses draft-07 (http://json-schema.org/draft-07/schema#). This is the most widely supported version and is compatible with AJV, Python's jsonschema library, and OpenAPI 3.0. If you need draft 2020-12, the generated schema is a solid starting point — most constructs are identical.

Can I use the schema for API validation?

Yes. The generated schema can be plugged directly into AJV (Node.js), Fastify's schema-based validation, Flask-JSONSchema (Python), or pasted into an OpenAPI spec under components/schemas. It validates structure and types out of the box.

How are required fields determined?

Every key present in the sample JSON is added to the required array. Since the generator works from a single example, it assumes all keys are required. If some fields are optional in practice, remove them from the required list after generation.

Does it handle arrays with mixed element types?

If all elements in an array are the same type, the schema uses a single items type. If elements are mixed (e.g. strings and numbers), it falls back to {} (any type) for items. You can refine this into a oneOf or anyOf after generation.

How do I extend the generated schema?

Add constraints like minLength, maximum, pattern (regex), or enum to individual properties. Add description fields for documentation. Use additionalProperties: false if you want to reject unknown fields. The generated schema is standard JSON — edit it in any text editor or with JSON Formatter.

Can I convert the schema to TypeScript types?

Yes. Tools like json-schema-to-typescript (npm) convert JSON Schema to TypeScript interfaces. You can also use the JSON to Zod tool to create a Zod schema from the same sample data, which gives you both runtime validation and static types.

How does it handle null values?

A field with a null value is typed with "type": ["null"] or a similar nullable representation. In practice you will usually want to specify the non-null type as well, e.g. "type": ["string", "null"], after generation.

Privacy & how it works

All schema generation runs entirely in your browser using client-side JavaScript. No JSON data is sent to any server, logged, or stored. You can verify this by checking your browser's network tab. This makes the tool safe for proprietary API responses, internal configs, or any data you do not want to share externally. Other tools like the JSON Formatter, JSON to Pydantic, and JSON Diff converter work the same way.