NC Logo 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.

Schema Options

About JSON Schema Generator

JSON Schema Generator automatically creates a JSON Schema definition from any JSON data you provide. JSON Schema is a powerful vocabulary that allows you to validate, annotate, and document JSON documents. It is widely used for API contract validation (OpenAPI/Swagger), form generation in UI frameworks, configuration file validation, and automated testing. Instead of writing JSON Schema by hand — which is tedious and error-prone — this tool analyzes your JSON data, infers types, detects common formats (email, URI, date-time, UUID, IP addresses), handles nested objects and arrays, and produces a clean, standards-compliant schema ready for production use.

How to Use

  1. Paste your JSON data into the input area (objects, arrays, or any valid JSON).
  2. Optionally set a schema title and choose the JSON Schema draft version.
  3. Toggle "Mark all fields required" to control whether properties are required.
  4. Toggle "Allow additional properties" to control strict vs. flexible validation.
  5. Click "Generate Schema" to produce the JSON Schema.
  6. Copy or download the generated schema for use in your project.

Features

The generator automatically detects string formats (email, URI, date-time, date, time, UUID, IPv4, IPv6), distinguishes between integer and number types, merges schemas from arrays of objects to create comprehensive item definitions, handles deeply nested structures, and supports all JSON Schema draft versions from Draft 04 to Draft 2020-12. For arrays with mixed types, the generator uses the oneOf keyword to accurately represent all possible item types.

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.

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 Tools