JSON to JSON Schema (Draft 2020-12) Generator Online

Generate JSON Schema Draft 2020-12 definitions from any JSON payload online. Infers required arrays, additionalProperties: false, integer vs number, and anyOf unions.

Input JSON

Generate Strict JSON Schema Draft 2020-12 for OpenAPI, Ajv & LLM Structured Outputs

JSON Schema Draft 2020-12 (https://json-schema.org/draft/2020-12/schema) is the standard contract format for Ajv request validation, OpenAPI 3.1 specifications, and LLM Structured Outputs / function-calling tool definitions (OpenAI, Gemini, Anthropic). Manually authoring deeply nested properties, required arrays, and additionalProperties: false rules is tedious and error-prone.

This pre-configured JSON Schema generator inspects your sample JSON document, distinguishes integer from floating-point number types, merges array item schemas to compute exact required property lists, and outputs a strict Draft 2020-12 schema locally in your browser.

  • Strict Object Contracts (required & additionalProperties: false): Automatically populates required with keys present across all sampled objects and sets additionalProperties: false for LLM structured output compatibility.
  • Nullable & Multi-Type anyOf Unions: Wraps nullable or heterogeneous fields in standard anyOf schemas.

Using Generated Schemas with Ajv Validator, OpenAPI 3.1 & AI Function Calling

OpenAPI 3.1 aligned its schema vocabulary 1:1 with JSON Schema Draft 2020-12, meaning you can paste the generated schema block directly under components.schemas in your openapi.yaml or pass it to Ajv (new Ajv2020({ allErrors: true, strict: true }).compile(schema)) for high-throughput Node.js request validation.

When building AI agents with OpenAI response_format: { type: "json_schema" }, Google Gemini responseSchema, or Anthropic tool input_schema, strict constrained decoding requires every object node to declare additionalProperties: false and list all mandatory keys in required—both of which this generator emits automatically.

  • Semantic integer vs number Type Distinction: Whole numbers in your sample payload emit "type": "integer" while decimal values emit "type": "number", preventing float-to-integer truncation bugs in downstream consumers.
  • Heterogeneous Array Item Merging: When an array contains multiple object snapshots, properties present in every element are placed in required while partial keys remain optional in properties.

Practical Real-World Use Cases

Platform, API, and AI engineers use generated Draft 2020-12 schemas to automate contract enforcement and structured generation:

  • OpenAI, Gemini & Anthropic Structured Output Schemas: Convert an example extraction JSON directly into a strict response_format / responseSchema contract with required arrays and additionalProperties: false.
  • OpenAPI 3.1 Specification & Fastify / Ajv Validation: Bootstrap components.schemas blocks for openapi.yaml files and compile high-speed Ajv request/response validators in Node.js microservices.
  • VS Code YAML/JSON Autocomplete ($schema) & Event Registries: Publish internal JSON Schema files for custom CI configuration files or Kafka Schema Registry contracts so IDEs highlight invalid keys inline.

Frequently Asked Questions

Which JSON Schema specification version does this generator output?

It outputs JSON Schema Draft 2020-12 ($schema: "https://json-schema.org/draft/2020-12/schema") with explicit type, properties, required, and additionalProperties: false fields.

Can I use the generated JSON Schema for OpenAI / Gemini Structured Outputs and Ajv?

Yes. Because every generated object schema includes explicit required arrays and additionalProperties: false, the output is directly compatible with LLM structured output APIs and Ajv strict mode.