UseToolSuite UseToolSuite

JSON Schema Generator

Generate JSON Schema from any JSON data automatically. Detects types, formats (email, URI, date-time, UUID), handles nested objects and arrays. Supports Draft 04 through Draft 2020-12.

Last updated

JSON Schema Generator is a free, browser-based tool from UseToolSuite's Format & Convert Tools collection. All processing happens locally on your device — your data is never uploaded to any server. Use the tool below, then scroll down for detailed documentation, frequently asked questions, and related resources.

Advertisement

Schema Options

What is the JSON Schema Generator?

The JSON Schema Generator is a powerful, locally-executing developer tool that automatically infers and generates strict JSON Schema definitions from sample JSON data. Writing schemas manually for complex APIs is a tedious and error-prone process. This tool dramatically accelerates backend development and API documentation by securely analyzing your payload in the browser. It intelligently detects types, nested objects, arrays, and string formats (like UUIDs, emails, and dates) without sending your proprietary data structures to an external server, guaranteeing the privacy of your API contracts.

How does it work?

The tool uses client-side JavaScript algorithms to recursively traverse your parsed JSON object. It analyzes the data types of each key, determines if an array contains uniform or mixed types (applying `oneOf` when necessary), and uses regular expressions to infer specific string formats. It then constructs a valid JSON Schema object (supporting multiple drafts) and formats it as a downloadable JSON string.

Common use cases

1. Instantly generating schema definitions for OpenAPI (Swagger) documentation based on real API response payloads.
2. Creating validation schemas for NoSQL databases (like MongoDB) to enforce document structure.
3. Building frontend form validation rules automatically derived from sample configuration files.

What the generator gives you — and what it doesn’t

Hand-writing JSON Schema for a large object is tedious and error-prone. This tool reads your sample JSON and emits a matching schema: correct types, nested objects, arrays, and detected string formats (email, URI, date-time, UUID, IPv4/6). That’s the structural skeleton — typically 80% of the work. What it can’t infer from a single sample are the things data alone doesn’t reveal:

Captured automaticallyYou add by hand
Types and nestingWhich fields are optional
Detected string formatsValue constraints (min/max, enum, pattern)
Array element shapesCross-field rules and descriptions
additionalProperties postureCustom error semantics

Picking a draft version

JSON Schema has evolved through several drafts, and the right choice depends on your toolchain:

  • Draft 2020-12 — newest and most capable; use it for new projects and OpenAPI 3.1 (which uses it natively).
  • Draft 07 — the most broadly supported across libraries; the safe default if you’re unsure your tools support 2020-12.
  • Draft 04 — legacy, but still required by OpenAPI 3.0’s schema subset.

The structural output is similar across versions; the main differences are the $schema URI and the availability of newer keywords.

Strict or lenient: additionalProperties

One decision shapes how forgiving your schema is. With "additionalProperties": false, an object must contain only the listed properties — any extra key fails validation, which catches typos and unexpected fields. Left at the default (true), extra properties are allowed, which suits extensible or evolving data. Use false for strict API contracts and config files where surprises are bugs; use the lenient default when forward-compatibility matters more than strictness.

Where the schema earns its keep

A finished schema is reusable across your stack: validate API requests and responses (Ajv and friends), auto-generate forms (React JSON Schema Form), validate config files (VS Code reads $schema), and document your data model in one authoritative place. Generate the shape here, harden it with constraints, and it becomes a single source of truth that keeps producers and consumers honest.

How helpful was this tool?

Click to rate

Advertisement

Key Concepts

Essential terms and definitions related to JSON Schema Generator.

JSON Schema

A declarative language for describing the structure of JSON data. A JSON Schema document is itself valid JSON and defines what types, formats, and constraints are allowed for each field in a JSON document. The current version is Draft 2020-12, maintained by the JSON Schema organization. It is widely used in API specifications (OpenAPI), configuration validation, form generation, and data documentation.

$schema Keyword

A special keyword at the root of a JSON Schema document that declares which version of the JSON Schema specification the schema conforms to. For example, "$schema": "https://json-schema.org/draft/2020-12/schema" indicates Draft 2020-12. Validators use this to determine which keywords and behaviors to support. Always include $schema for maximum compatibility.

oneOf / anyOf / allOf

Composition keywords in JSON Schema for combining multiple schemas. "oneOf" means the data must match exactly one of the listed schemas. "anyOf" means the data must match at least one. "allOf" means the data must match all of them. These are used for polymorphic types, union types, and schema inheritance. This tool uses "oneOf" for arrays containing items of different types.

additionalProperties

A JSON Schema keyword that controls whether an object can contain properties not listed in the "properties" keyword. When set to false, any unlisted property causes validation to fail. When set to true (or a schema), unlisted properties are allowed (or must match the given schema). Setting it to false creates strict, closed schemas that catch typos and unexpected fields.

Frequently Asked Questions

What is JSON Schema and why do I need it?

JSON Schema is a vocabulary for annotating and validating JSON documents. It defines the expected structure, types, and constraints of your JSON data — like a contract or blueprint. JSON Schema is used for: API validation (OpenAPI/Swagger specs), form generation in UI frameworks (React JSON Schema Form), configuration file validation (VS Code settings, ESLint configs), automated testing (validating API responses), and documentation (describing your data model). Instead of writing schemas by hand, this tool generates them automatically from example data.

Which JSON Schema version should I use?

Draft 2020-12 is the latest and most feature-rich version, recommended for new projects. Draft 07 is the most widely supported across tools and libraries — use it if your toolchain does not yet support 2020-12. Draft 04 is legacy but still used by some older systems (including some OpenAPI 3.0 implementations). The generated schema is functionally similar across versions — the main differences are the $schema URI and availability of newer keywords.

What string formats does the tool detect?

The tool automatically detects: date-time (ISO 8601, e.g., "2024-01-15T10:30:00Z"), date ("2024-01-15"), time ("10:30:00"), email ("user@example.com"), URI ("https://example.com"), IPv4 ("192.168.1.1"), IPv6 ("::1"), and UUID ("550e8400-e29b-41d4-a716-446655440000"). Format annotations help validators and UI generators understand the semantic meaning of string fields.

How does the tool handle arrays with mixed types?

If all items in an array are the same type (e.g., all strings or all integers), the schema uses a single "items" definition. If items are objects with different shapes, the tool merges their schemas to create a comprehensive item definition that covers all possible fields. If items are fundamentally different types (e.g., strings mixed with numbers), the tool uses the "oneOf" keyword to describe all possible item schemas.

What does "additionalProperties: false" mean?

When set to false, "additionalProperties" means the JSON object must contain only the properties defined in the schema — any extra properties will fail validation. This creates strict validation. When set to true (or omitted), additional properties beyond those listed in the schema are allowed. Use false for strict API contracts and configuration validation; use true for extensible data models.

Can I use the generated schema with OpenAPI/Swagger?

Yes. The generated JSON Schema is compatible with OpenAPI 3.1 (which uses JSON Schema Draft 2020-12 natively) and can be adapted for OpenAPI 3.0 (which uses a subset of JSON Schema Draft 04). For OpenAPI 3.0, use the Draft 04 version option and you may need to remove the $schema property. The schema can be placed directly in the "components/schemas" section of your OpenAPI spec.

The generated schema marks every field as required — how do I fix that?

The generator infers the schema from one sample of data, and since every key is present in that sample, it lists them all in the 'required' array. Real data usually has optional fields, so after generating, edit the 'required' array to keep only the keys that must always be present, and remove the rest (a property not listed in 'required' is treated as optional). If you want the schema to reflect optionality automatically, feed it a sample that omits the optional fields — but hand-editing the required array is the precise, reliable way to express your actual contract.

How do I add validation rules like min/max, patterns, or enums?

A generated schema captures structure and types but not business rules — those you add by hand, and JSON Schema has rich vocabulary for them. For numbers use minimum/maximum (or exclusiveMinimum/Maximum); for strings use minLength/maxLength and pattern (a regex, e.g. for a phone format); for fixed sets use enum ("status": { "enum": ["active", "inactive"] }); for arrays use minItems/maxItems/uniqueItems. Generate the structural skeleton with this tool, then layer these constraints onto the fields that need them. That two-step approach — generate the shape, hand-add the rules — is the normal workflow.

Troubleshooting & Technical Tips

Common errors developers encounter and how to resolve them.

Schema does not match expected validation behavior

The generated schema reflects the structure of the specific JSON data you provided. If your data has optional fields, they may not appear in the schema unless they are present in the input. To ensure all possible fields are included, provide a JSON example that contains every field your data model supports, including optional ones.

Integer detected instead of number

The tool uses "integer" for whole numbers (42) and "number" for decimal values (3.14). If your field should accept both, you may need to manually change "integer" to "number" in the generated schema, or provide a decimal value in your example data.

Format not detected for a string field

The format detector uses pattern matching. If a string looks like an email but has an unusual TLD, or a URL uses a non-standard protocol, it may not be detected. You can manually add the "format" annotation to the generated schema for these edge cases.

Related Guides

In-depth articles covering the concepts behind JSON Schema Generator.

Advertisement

Related Tools