Schema Toolkit · 100% Local · Browser Only

    JSON Schema to OpenAPI

    Generate OpenAPI 3.1 components, GET examples, POST request bodies, and YAML/JSON export from a JSON Schema.

    Browser only Valid Schema / Data
    JSON Schema
    23 lines
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    OpenAPI 3.1 Spec
    201 lines
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201

    Schema Metrics

    Fields
    12
    Objects
    2
    Arrays
    1
    Constraints
    4

    Field Hierarchy Tree

    Root(object)
    └─id*(integer)
    └─name*(string)
    └─email*(string)
    email
    └─active(boolean)
    └─createdAt(string)
    date-time
    └─profile(object)
    └─phone(string)
    └─country(string)
    └─company(string)
    └─roles(array)
    └─items[](string)

    Schema Constraints

    $.name(1 rule)
    minLength:1
    $.email(1 rule)
    format:email
    $.createdAt(1 rule)
    format:date-time
    $.roles[](1 rule)
    enum:["admin","developer","member"]
    OpenAPI 3.0 & 3.1 Spec Generator
    Swagger UI & Redoc Compatible

    Convert JSON Schema to OpenAPI 3.0, 3.1 & Swagger YAML

    Convert JSON Schema specifications into OpenAPI 3.0 YAML, OpenAPI 3.1 JSON, and Swagger 2.0 definitions. Easily generate components/schemas, REST path operation payloads (requestBody & responses), and OpenAPI specifications for Swagger UI, Redoc, Postman, and AWS API Gateway.

    OpenAPI Specs3.0.3 & 3.1.0 Ready
    Legacy SupportSwagger 2.0 YAML
    Nullable Mappingnullable: true Conversion
    Privacy100% Client-Side

    Interactive OpenAPI Output Modes

    Select a target OpenAPI / Swagger format to inspect input JSON Schema and generated spec YAML:

    OpenAPI 3.0 YAML
    Input JSON Schema

    1. OpenAPI 3.0 YAML Component Schema

    Converts JSON Schema Draft-07 objects into OpenAPI 3.0 YAML component schemas, mapping `type: ['string', 'null']` to OpenAPI 3.0 `nullable: true`.

    Source JSON Schema
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": ["userId", "email"],
      "properties": {
        "userId": { "type": "integer" },
        "email": { "type": "string", "format": "email" },
        "role": { "type": "string", "enum": ["ADMIN", "USER"] },
        "bio": { "type": ["string", "null"] }
      }
    }
    Generated OpenAPI Spec YAML / JSON
    openapi: 3.0.3
    components:
      schemas:
        UserProfile:
          type: object
          required:
            - userId
            - email
          properties:
            userId:
              type: integer
            email:
              type: string
              format: email
            role:
              type: string
              enum:
                - ADMIN
                - USER
            bio:
              type: string
              nullable: true
    Spec Conversion Rules

    JSON Schema vs OpenAPI 3.0 vs OpenAPI 3.1 Mapping Matrix

    Comparison matrix detailing keyword translation rules across JSON Schema and OpenAPI specifications:

    Feature / KeywordJSON Schema StandardOpenAPI 3.0 TranslationOpenAPI 3.1 Translation
    Schema Container$defs / definitionscomponents/schemascomponents/schemas
    Nullable Stringstype: ["string", "null"]type: string, nullable: truetype: ["string", "null"]
    Schema Header$schema URIopenapi: 3.0.3openapi: 3.1.0
    ID Identifier$id: '...' Removed (uses object key)$id / $anchor supported
    Sample Valuesexamples: [...]example: '...'examples: [...]
    Read-Only FieldsreadOnly: truereadOnly: truereadOnly: true

    Why, When, & How to Convert JSON Schema to OpenAPI

    Why Convert to OpenAPI?

    OpenAPI (Swagger) is the universal industry standard for REST API documentation, interactive UI sandboxes (Swagger UI / Redoc), SDK client generation, and API Gateway request validation.

    When to Use the Converter?

    Use when publishing public API documentation portals, generating OpenAPI contracts for Postman collections, configuring AWS API Gateway validation, and designing microservice contracts.

    How Does the Generator Work?

    Paste your JSON Schema. The converter translates `$defs` into `components/schemas`, handles OpenAPI 3.0 `nullable: true` rules, and formats a validated OpenAPI 3.0 or 3.1 YAML document in real time.

    Programmatic Conversion Code Examples

    Convert JSON Schema to OpenAPI in Node.js scripts, Python pipelines, and CLI builds:

    const { toOpenApi } = require('@openapi-contrib/json-schema-to-openapi-schema');
    
    const jsonSchema = {
      type: 'object',
      required: ['id', 'name'],
      properties: {
        id: { type: 'integer' },
        name: { type: 'string' },
        email: { type: ['string', 'null'], format: 'email' }
      }
    };
    
    // Convert JSON Schema Draft-07 to OpenAPI 3.0 Schema
    const openApiSchema = toOpenApi(jsonSchema);
    
    console.log(JSON.stringify(openApiSchema, null, 2));
    /* Output:
    {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": { "type": "integer" },
        "name": { "type": "string" },
        "email": { "type": "string", "nullable": true, "format": "email" }
      }
    }
    */

    Frequently Asked Questions (FAQs)

    Related Developer Tools

    Explore more free developer tools to speed up debugging, testing, and development.