Skip to content
Advanced

JSON Schema vs OpenAPI Schema: What Is the Difference?

·5 min read
JSON Schema vs OpenAPI Schema: What Is the Difference? - Advanced guide from JSON Prettifier

Quick answer: JSON Schema describes and validates JSON values. An OpenAPI document describes an HTTP API, and its Schema Objects describe the request and response data inside it. OpenAPI 3.0 uses its own schema dialect that differs from standard JSON Schema (for example nullable: true and a single-string type), while OpenAPI 3.1 aligns its Schema Object with JSON Schema Draft 2020-12 plus a small OpenAPI-specific vocabulary.

A developer copies a JSON Schema into an OpenAPI specification and the validator rejects it. Another developer upgrades the OpenAPI document and discovers that nullable no longer works as expected. Neither problem is random.

Inspect the JSON structure in the JSON Viewer. This helps with reading the payload; schema validation still requires a separate schema validator.

First, what does JSON Schema do?

Imagine an order sent by your frontend:

{"id":1042,"status":"paid","total":249.5}

JSON Schema can describe the expected structure:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "status": { "type": "string", "enum": ["pending", "paid"] },
    "total": { "type": "number", "minimum": 0 }
  },
  "required": ["id", "status", "total"]
}

The sample JSON may be syntactically valid even if it fails these rules. That is why syntax validation and schema validation are separate tasks. If the keywords above are new to you, the JSON Schema explained guide walks through type, properties, required, and the rest of the core vocabulary.

What does OpenAPI add?

When an OpenAPI contract changes after clients depend on it, use the guide to JSON API versioning mistakes to coordinate contract diffs, generated SDK tests, deprecation dates, and measured retirement.

An OpenAPI description can explain much more than the JSON body: endpoint paths, HTTP methods, parameters, response codes, request bodies, authentication schemes, and server details.

For example, OpenAPI can document GET /orders/{id} and describe its 200 response using a schema. JSON Schema by itself does not document the entire HTTP exchange. In OpenAPI, the schema sits under a media type, so the same endpoint can declare that its body is application/json (see the JSON Content-Type guide) and document a separate schema for its error responses:

paths:
  /orders/{id}:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

The important version difference

This is where mistakes tend to happen:

FeatureOpenAPI 3.0 Schema ObjectOpenAPI 3.1 Schema Object
Relationship to JSON SchemaAn extended subset of an older JSON Schema draft (Wright Draft 00)A full JSON Schema Draft 2020-12 document plus the OAS vocabulary
Nullable fieldnullable: true alongside a single typetype: ["string", "null"]
type keywordMust be a single stringMay be a string or an array of types
exclusiveMinimum / exclusiveMaximumBooleans that modify minimum / maximumNumbers, as in modern JSON Schema
Examplesexample (single value)examples (array, from JSON Schema); example is deprecated
Unsupported in 3.0patternProperties, const, if/then/else, contains, propertyNames, $schemaAll supported; $schema may select a dialect per schema
Best migration adviceCheck 3.0-specific rulesValidate against the actual 3.1 tooling in use

For example, an OpenAPI 3.0-style property might be:

website:
  type: string
  nullable: true

In an OpenAPI 3.1 schema, the JSON Schema way is:

website:
  type:
    - string
    - 'null'

That is not a universal find-and-replace instruction. Review the entire schema and validator compatibility during migration. The semantics of null itself, and how it differs from an absent key, are covered in the JSON null vs undefined guide.

Two more details matter when you move to 3.1. First, the top-level jsonSchemaDialect field declares the default dialect for every Schema Object in the document; when it is omitted, the OAS 3.1 base dialect applies, which is JSON Schema 2020-12 plus the OpenAPI keywords. Second, format values such as date-time, email, and uuid are annotations in JSON Schema unless the validator is configured to assert them, so do not assume a schema rejects a malformed timestamp just because format: date-time is present (the JSON date format guide explains why that field is a string in the first place).

A syntax validator cannot check your API contract

Suppose your API sends:

{"id":"1042","status":"paid","total":-20}

This is valid JSON syntax. But the schema above expects an integer id and a nonnegative total, so the data fails schema validation.

A tool such as JSON Prettifier is useful for identifying missing quotes, trailing commas and confusing nesting. For the contract itself, use a JSON Schema/OpenAPI validator that understands the dialect used by your project.

Which should you choose?

If your immediate problem is validating a configuration file, message payload or generic JSON document, JSON Schema may be sufficient. If you are documenting and tooling a REST API with endpoints, parameters and authentication, OpenAPI is usually the more complete description format.

They're not competing choices in every situation. You can use schemas to define the data portions of an OpenAPI contract and reuse compatible schema definitions across validation and documentation workflows—with attention to version compatibility. With OpenAPI 3.1 that reuse is straightforward, because a 2020-12 schema file can be referenced from components/schemas without translation; with 3.0 it usually means maintaining a trimmed copy.

If you're just learning syntax, start with What is JSON?. For API structures, see JSON in REST APIs. For malformed text, read common JSON errors.

Primary references for implementation decisions: JSON Schema specification and OpenAPI specification. Check the specification version relevant to your project.

The safe decision isn't to pick the schema format with the shortest file. Pick the one that describes your actual contract, then validate examples with tooling that understands the same version and dialect.

For the next review step, check these eight JSON Schema validation mistakes, including dialect mismatches, non-asserted formats, overlapping oneOf branches, and closed-schema composition.

Frequently Asked Questions

Is OpenAPI the same as JSON Schema?
No. JSON Schema describes and validates a JSON value. OpenAPI describes a whole HTTP API (paths, methods, parameters, responses, security) and uses Schema Objects, which are based on JSON Schema, to describe the request and response bodies within it.
Can I paste any JSON Schema into an OpenAPI 3.0 document?
No. OpenAPI 3.0's Schema Object is an extended subset of an older JSON Schema draft. It lacks keywords such as patternProperties, const, and if/then/else, requires type to be a single string, and adds its own nullable and discriminator keywords.
Is OpenAPI 3.1 identical to JSON Schema?
Almost. OpenAPI 3.1 Schema Objects are full JSON Schema Draft 2020-12 documents with a small OpenAPI vocabulary added (discriminator, xml, externalDocs, example). Tool support still varies, so validate with the tooling your project actually uses.
How do I make a field nullable in OpenAPI 3.1?
Use a type array, for example type: [string, "null"], exactly as in JSON Schema. The nullable keyword from OpenAPI 3.0 was removed in 3.1 and is ignored or rejected by 3.1 validators.
Does valid JSON automatically pass an OpenAPI schema?
No. Valid JSON only means the text parses. A schema can still reject it for a wrong type, a missing required property, a value outside an enum, or a number below a minimum, so syntax validation and schema validation are separate steps.

Check the example before you check the schema

Paste a request or response sample into JSON Prettifier to confirm it parses and to sort keys so it lines up with your schema's properties list. It runs in your browser; nothing leaves your machine.

Validate the sample JSON