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.0 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 → oneOf null: OpenAPI nullable: true becomes {"oneOf": [schema, {"type": "null"}]} — standard JSON Schema syntax
$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 converted to JSON Schema Draft 7 with nullable as oneOf and updated $ref paths:

{
  "$schema": "https://json-schema.org/draft-07/schema",
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "active": {
      "oneOf": [
        { "type": "boolean" },
        { "type": "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. In JSON Schema Draft 7, this is expressed as {"oneOf": [schema, {"type": "null"}]}. 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?

The output targets JSON Schema Draft 7, which is the most widely supported version and is what AJV, react-jsonschema-form, and most other tools default to. The $schema keyword is set to the Draft 7 URI.

How is OpenAPI nullable handled?

OpenAPI's nullable: true extension is converted to a {"oneOf": [originalSchema, {"type": "null"}]} construct — the correct JSON Schema Draft 7 way to allow null. Note that JSON Schema 2019-09+ uses type: ["string", "null"] instead, but Draft 7 requires the oneOf approach.

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

Use the dropdown in the output panel to select a specific schema by name, or choose "All schemas (bundled)" to get a single document with all schemas in a $defs block. The bundled document is needed when schemas reference each other via $ref.

Does it support allOf, oneOf, anyOf?

Yes. allOf, oneOf, and anyOf are all preserved in the output and are fully valid JSON Schema. Nested schemas within these keywords are recursively converted. Read more about OpenAPI composition keywords.

Which validators accept this JSON Schema output?

AJV (JavaScript), jsonschema (Python), and gojsonschema (Go) all work with Draft 7. For TypeScript, use json-schema-to-typescript to generate types from the output.

Does it support Swagger 2.0 as well as OpenAPI 3.0?

Yes. For Swagger 2.0 specs, schemas are read from the definitions object and $ref paths are rewritten from #/definitions/ to #/$defs/. You can also use our Swagger to OpenAPI converter first if you prefer to work with a 3.0 spec.

Is this OpenAPI to JSON Schema converter free?

Yes, completely free with no limits on spec size or number of schemas. No registration required. All conversion runs in your browser — your spec never leaves your device.