Loading OpenAPI to JSON Schema Converter...

How to Convert OpenAPI Schemas to JSON Schema - Step by Step Guide

Extract and normalise OpenAPI component schemas to standard JSON Schema Draft 7 for use with validators, code generators, and form libraries

Step 1

Paste Your OpenAPI Specification

Paste your OpenAPI 3.x or Swagger 2.0 spec in JSON or YAML. The converter reads all schemas from components/schemas (or definitions for Swagger 2.0) and converts them to JSON Schema Draft 7:

•
Paste directly: Copy your spec from Swagger Editor or your API design tool
•
Upload a file: Load an openapi.json, swagger.yaml, or .yml file from disk
•
Select a schema: Use the dropdown to view one schema or bundle all into a single $defs document

Example: OpenAPI Schema with nullable and $ref

A User schema with OpenAPI-specific nullable and a $ref to a Profile schema:

components:
  schemas:
    User:
      type: object
      required: [id, email]
      properties:
        id: { type: integer }
        active:
          type: boolean
          nullable: true
        profile:
          $ref: '#/components/schemas/Profile'
Step 2

Auto-Generated JSON Schema Output

Each OpenAPI schema is normalised to standard JSON Schema Draft 7. Key transformations applied:

•
nullable → null in the type list: type: boolean with nullable: true becomes "type": ["boolean", "null"]; a nullable $ref is wrapped in anyOf
•
$ref path rewriting: #/components/schemas/X → #/$defs/X to match JSON Schema's $defs convention
•
OpenAPI extensions removed: xml, discriminator, and externalDocs fields are stripped as they are not part of JSON Schema
•
example → examples: OpenAPI example (singular) is converted to JSON Schema examples (array)

Example: Generated JSON Schema Output

The User schema above as JSON Schema Draft 7 (trimmed; the real output also carries the other schemas under $defs):

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "active": { "type": ["boolean", "null"] },
    "profile": { "$ref": "#/$defs/Profile" }
  }
}
Step 3

Download and Use in Your Validation Pipeline

Download the JSON Schema file and plug it into any JSON Schema validator:

•
AJV (Node.js): The most popular JSON Schema validator — use the generated file to validate API request/response payloads at runtime before they reach your business logic
•
react-jsonschema-form: Pass the schema directly as the schema prop — your API models instantly become auto-rendered, validated data entry forms
•
Contract testing in CI: Add the schema file to your repo and use Jest + AJV in GitHub Actions to assert that API responses always match the spec — catching breaking changes before they reach production

What is OpenAPI to JSON Schema Conversion?

OpenAPI schemas are based on JSON Schema but include extensions (nullable, discriminator, xml) and restrict some keywords. Validators like AJV and form generators like react-jsonschema-form expect pure JSON Schema. This converter bridges the gap by extracting components/schemas and normalising them to JSON Schema Draft 7.

The primary difference is nullable: true — OpenAPI's way of allowing null values. JSON Schema has no such keyword; it lists null as one of the allowed types instead. The converter also rewrites $ref paths from #/components/schemas/ to #/$defs/, removes OpenAPI-only fields (xml, discriminator), and converts singular example to the JSON Schema examples array.

The output schema includes a $defs block containing all converted schemas so that $ref cross-references resolve correctly. For bundled multi-schema output, a root document with $schema and $defs is generated — compatible with AJV's schema management. Validate your spec first with our OpenAPI Validator.

Common Use Cases

Runtime Request Validation

Extract JSON schemas from your OpenAPI spec and use AJV to validate incoming API requests in your Node.js server — ensuring payloads match the spec before processing. Pair with our OpenAPI to TypeScript converter for compile-time safety too.

Form Generation

Use the extracted JSON Schema with react-jsonschema-form or React Hook Form resolvers to auto-generate data entry forms directly from your API models — keeping forms and API contracts in sync. Start with our JSON to OpenAPI tool if you're building from scratch.

Frequently Asked Questions

What JSON Schema draft does the output use?

For OpenAPI 3.0 and Swagger 2.0 specs the output is JSON Schema Draft 7, and $schema is set to http://json-schema.org/draft-07/schema#. OpenAPI 3.1 schemas already are JSON Schema 2020-12, so for a 3.1 spec the output says 2020-12 instead and the schemas pass through almost untouched.

How is OpenAPI nullable handled?

nullable: true is removed and "null" is added to the allowed types, so type: string becomes type: ["string", "null"]. If the schema has an enum, null is added to the list too. When there is no type to extend, for example a $ref with nullable next to it, the schema is wrapped as anyOf: [the original, { type: null }].

What else gets changed on the way?

$ref paths move from #/components/schemas/ or #/definitions/ to #/$defs/, example becomes a one-item examples array, and the boolean exclusiveMinimum / exclusiveMaximum from OpenAPI 3.0 turn into the numeric form JSON Schema expects (minimum: 0 plus exclusiveMinimum: true becomes exclusiveMinimum: 0). xml, discriminator and externalDocs are dropped. Numbers such as default, enum and maximum values are copied exactly as written, so 8901240544102066246 or 14.50 stay as they are.

Can I extract a single schema or must I take all of them?

Pick a schema by name from the dropdown above the output, or keep "All schemas (bundled)" for one document with everything under $defs. A single schema still carries the other schemas in its $defs block, so any $ref inside it keeps resolving.

Which validators accept the output?

We check the output with AJV. Python jsonschema and gojsonschema read Draft 7 as well, and json-schema-to-typescript can turn the file into TypeScript types. Vendor extensions such as x-something are left in place, so run AJV with strict mode off or remove them first.

Does it support Swagger 2.0 as well as OpenAPI 3?

Yes. For Swagger 2.0 the schemas come from the definitions object, and type: file (which JSON Schema has no word for) becomes a string with format binary. If you want to move the whole spec to OpenAPI 3.0, the Swagger to OpenAPI converter does that.

Is my spec uploaded anywhere?

No. The conversion runs in your browser and the spec is not sent to a server. The page is free and needs no sign-up.

Related: Swagger to OpenAPI · JSON Schema to OpenAPI (the other direction) · OpenAPI Validator