Home → JSON to OpenAPI Schema Generator

JSON to OpenAPI Schema Generator

Generate OpenAPI 3.0 schema definitions from a sample JSON response.

About This Tool

Generate OpenAPI 3.0 schema definitions from a sample JSON response. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.

What OpenAPI Specification Is

OpenAPI (formerly Swagger) is the industry standard for describing REST APIs in a machine-readable format.

OpenAPI Schema Objects

OpenAPI uses JSON Schema-like syntax to describe request bodies, response bodies, and query parameters. Schema objects define field names, types, formats, required status, and constraints like minimum, maximum, and pattern.

OpenAPI Versions

The tool generates schemas for both OpenAPI 3.0 and 3.1. Version 3.1 is fully JSON Schema compatible (draft 2020-12), while 3.0 uses a superset with some differences. Choose the version your toolchain supports.

From JSON Sample to OpenAPI Schema

The tool infers a complete OpenAPI schema from your JSON example, handling type detection and structure automatically.

Request Body Schemas

Generate the requestBody schema for a POST or PUT endpoint from a sample request body. The output is ready to paste into your OpenAPI spec under the requestBody.content.application/json.schema path.

Response Schemas

Generate a 200 OK response schema from a sample API response. Paste the output under responses.200.content.application/json.schema in your spec, or add it to components.schemas for reuse.

Frequently Asked Questions

What is an OpenAPI schema?+
An OpenAPI schema is the part of an OpenAPI (Swagger) specification that describes the structure of a JSON request or response body. It defines required fields, data types, formats, and constraints. OpenAPI schemas are used by API documentation tools, code generators, and API testing tools.
How do I use the generated OpenAPI schema?+
Copy the generated schema object and paste it into your OpenAPI specification file as a component schema or inline schema. If you are using Swagger UI or Redoc, the schema will render as interactive documentation. Reference it using $ref: '#/components/schemas/MyObject' to reuse it across multiple endpoints.
What is the difference between OpenAPI 3.0 and 3.1 schemas?+
OpenAPI 3.1 schemas are fully compatible with JSON Schema draft 2020-12. OpenAPI 3.0 uses a subset of JSON Schema with some differences — for example, nullable is used instead of the JSON Schema type array with null. If you are using a modern API toolchain, prefer 3.1.
Can I generate a full OpenAPI spec from JSON?+
This tool generates the schema objects from JSON samples — the most tedious part to write by hand. A complete OpenAPI spec also requires endpoint paths, HTTP methods, parameter definitions, and security schemes, which must be written manually or generated from your codebase.

JSON to OpenAPI Schema Conversion

OpenAPI (formerly Swagger) is the industry standard for documenting REST APIs. Converting JSON response examples into OpenAPI schemas automates the documentation process.

JSON Input → OpenAPI 3.0 Schema

// JSON API Response
{"id": 1, "name": "Alice", "email": "alice@example.com", "isPremium": true}

// OpenAPI 3.0 Schema
components:
  schemas:
    User:
      type: object
      required:
        - id
        - name
        - email
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: Alice
        email:
          type: string
          format: email
          example: alice@example.com
        isPremium:
          type: boolean
          example: true

OpenAPI JSON Type Mappings

JSON TypeOpenAPI SchemaNotes
stringtype: stringAdd format: email, uri, date, etc.
integertype: integer, format: int32/int64
floattype: number, format: float/double
booleantype: boolean
nullnullable: trueOpenAPI 3.0; use type: [T, "null"] in 3.1
arraytype: array, items: {type: ...}
objecttype: object, properties: {...}
date stringtype: string, format: date-timeISO 8601

Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff

Understanding Generated OpenAPI Schemas

The converter inspects each JSON value type and emits the corresponding OpenAPI 3.0 schema definition. The example below shows an input JSON object and the fully-generated schema component that you can paste directly into your OpenAPI specification.

// Input JSON example
{"id": 1, "name": "Alice", "email": "alice@example.com", "active": true, "score": 9.5, "tags": ["admin"]}
# Generated OpenAPI 3.0 schema
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        email:
          type: string
        active:
          type: boolean
        score:
          type: number
        tags:
          type: array
          items:
            type: string

Using OpenAPI Schemas in API Documentation

Once you have a generated schema component, you can reference it across your entire OpenAPI document using $ref. This avoids repeating the schema in every endpoint and keeps your spec DRY. The example below shows a complete minimal OpenAPI spec with a GET /users/{id} endpoint referencing the generated User schema.

openapi: 3.0.0
info:
  title: My API
  version: 1.0.0
paths:
  /users/{id}:
    get:
      summary: Get user by ID
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: User found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      # — paste generated schema here —