Skip to main content
VVertex Solutions
All toolsPDF ToolsImage ToolsText ToolsCalculatorsDeveloperBlog
VVertex Solutions

Browse tools for merging and compressing PDFs, resizing and converting images, formatting text and JSON, running calculators, and working with code.

Popular Tools

  • Mortgage Calculator
  • GPA Calculator
  • Tip Calculator
  • BMI Calculator
  • Percentage Calculator
  • EMI Calculator
  • Merge PDF
  • JSON Formatter

Categories

  • All tools
  • PDF Tools
  • Image Tools
  • Text Tools
  • Calculators
  • Developer Tools

Company

  • About
  • About the Author
  • Editorial Standards
  • How We Verify Tools
  • How Data Is Processed
  • Calculator Comparisons
  • Disclaimer
  • Privacy Policy
  • Cookie Policy
  • FAQ
  • Accessibility
  • Changelog
  • Terms of Service
  • Contact
  • Blog
  • RSS Feed

© 2026 Vertex Solutions. All rights reserved.

Free tools. No signup. Privacy first.

  1. Home
  2. Blog
  3. JSON Schema Validation in API Workflows
Developerinformational4 min readPublished 2026-07-06 · Last updated 2026-10-23

JSON Schema Validation in API Workflows

JSON Schema checks request and response shapes before your code runs. Use it in CI, at the gateway, and in docs so contract drift shows up early.

By Rehan Baqir

Quick answer

JSON Schema describes types, required fields, enums, and formats for a JSON document. Validate requests at the API boundary and validate fixtures in CI so a string sent where a number belongs returns 400 with a path, not a 500 later. Schema does not check database state or whether a coupon is still valid.

JSON Schema checks the shape of a request or response before business code runs. JSON Validator can tell you the text parses. It will not reject "quantity": "12" when the contract requires an integer. Schema covers types, required fields, enums, and formats. It does not know whether a coupon is expired or whether that user owns the cart. Put the check at the API boundary, and run the same schemas against fixtures in CI, or a string from a form field becomes a 500 inside billing.

Production 500s have traced back to quantity: "12", a string where a number belonged. Server TypeScript types were wrong. The client looked fine until a new mobile build sent strings from a form field. Nothing at the boundary rejected the body.

A schema at the door can return 400 Bad Request with a clear path: /quantity expected number.

Validation layers

| Layer | When | Catches | | --- | --- | --- | | CI fixtures | PR merge | Doc/sample drift | | Unit tests | Dev | Handler edge cases | | Runtime middleware | Request hit | Bad clients | | Response tests | PR | Breaking API changes | | Gateway (Kong, etc.) | Edge | External traffic |

Use more than one layer. A single check leaves a gap the others were meant to cover.

Authoring schemas

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["email", "quantity"],
  "properties": {
    "email": { "type": "string", "format": "email" },
    "quantity": { "type": "integer", "minimum": 1 }
  },
  "additionalProperties": false
}

additionalProperties: false catches typos early. Public APIs sometimes leave it open for forward compatibility. Decide that internally.

Craft fixtures in JSON Formatter and check them with JSON Validator.

See JSON Formatting Guide and Common JSON Formatting Errors.

OpenAPI as source

Define components.schemas, generate TypeScript types with openapi-typescript, and generate validators with ajv.

Drift shows up when code changes and the spec does not. CI has to validate samples against the spec.

CI workflow example

  1. Keep openapi.yaml in the repo
  2. Keep example files such as examples/create-order.json
  3. Add a CI step: ajv validate -s schema -d examples/*.json
  4. In contract tests, assert the supertest response with .toMatchSchema()

Pretty-print the failures. JSON Pretty Print CI covers redacting tokens.

Runtime (Node example)

import Ajv from "ajv";
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(orderSchema);

if (!validate(req.body)) {
  return res.status(400).json({ errors: validate.errors });
}

Return RFC 7807 problem+json so the error is explicit.

Versioning schemas

Freeze /v1/ schemas. Put additive changes on /v2/. Do not mutate a v1 schema in a breaking way. Add a new schema file.

UUID v4 vs v7 is the companion note for format: uuid in a schema.

JSON Schema vs JSONL

JSON vs JSONL: line-delimited logs need a schema check per line inside the stream processor.

Regex in schema

A pattern for codes should be tried in Regex Tester. Regex Email Truth shows where format checks go wrong.

Performance

Compile schemas once at startup. On a large payload, validate structure before you run deep business rules.

Partial validation for webhooks

Stripe-style webhooks can validate the event envelope first, then hand the nested object to a handler that has a schema for that event type. Fail fast on a malformed envelope. Keep the payload checks in the typed handler.

Schema versioning in CI

schemas/v1/order.json and schemas/v2/order.json can live together. CI should validate examples/v1/ against the matching version. Otherwise a v2 example can pass against the v1 schema by accident.

Error response quality

Return a JSON Pointer in the validation error: {"path": "/quantity", "message": "expected number"}. Mobile clients can highlight the field. A generic "validation failed" creates more support tickets.

Worked example: catching a string-vs-number bug at the API gateway

Suppose a checkout client sends "quantity": "2" (a string from an HTML <input>) where the API expects "quantity": 2 (an integer):

  • Syntax check (JSON Validator): passes, because "2" is valid JSON syntax.
  • JSON Schema check ("type": "integer", "minimum": 1): fails immediately with instancePath: "/quantity", message: "must be integer". The bad payload stops before downstream billing code concatenates "2" + 1 into "21".

Limitations

JSON Schema validates structure, types, and formats. It does not validate database state or cross-service business rules. It can verify that coupon_code is a 6-to-12-character uppercase string and that user_id is a well-formed UUID. Application logic still has to check whether that coupon is expired and whether that user owns the cart.

Conclusion

Keep a schema at the boundary and fixtures in CI. TypeScript types on the server do not survive the hop over HTTP.

Return 400 with a path. A quantity sent as a string should die at the door, before accounting sees it.

Related Tools

Free browser-based tools referenced in this article.

Featured
JSON Formatter
JSON formatter to pretty-print or minify JSON. Use JSON Validator when you only need the error.
JSON Validator
JSON validator that parses input and reports the syntax error. It does not reindent the document.
Featured
Regex Tester
Regex tester for JavaScript RegExp, with flags and match indexes. Other engines can differ.

Key takeaways

  • JSON Schema describes expected structure: types, required fields, enums, and formats.
  • Validate at runtime and in CI. Runtime stops bad clients. CI catches schema regressions when code changes. A gateway is an optional extra layer.
  • OpenAPI 3.x embeds JSON Schema, with subset and dialect differences, for request and response models.
  • On pull requests, validate example fixtures, run contract tests against schema files, and lint the OpenAPI spec.

Frequently Asked Questions

Common questions answered to help you get the most from this tool.

JSON Schema describes the expected structure: types, required fields, enums, and formats. Validators check incoming requests and outgoing responses against that schema before business logic runs, and again in CI after code changes.

Do both. Runtime validation at the API boundary protects production from a bad client. CI validation against fixtures catches a schema regression when the code changes. Gateway validation is an optional extra layer.

OpenAPI 3.x embeds JSON Schema, with subset and dialect differences, for request and response models. One OpenAPI document can generate schemas, docs, and validators. Keep those outputs in sync.

On pull requests. Validate example fixtures, run contract tests against the schema files, and lint the OpenAPI spec. Fail the build if a response sample does not match the schema you declared.

JSON Formatter and JSON Validator help you build fixtures. The schema itself is JSON, so format it for review. Pretty-print CI failures, and redact tokens, using the CI JSON logging guide.

About the author

Rehan Baqir is the founder & editor of Vertex Solutions. He builds browser-based tools and writes guides about PDF workflows, calculators, image tools, and developer utilities. Article pages show their publication and update dates when available. Read the editorial standards and tool-testing method for the site's stated approach to content and verification.

More about Rehan Baqir →

json-schemaapivalidationciopenapi
Back to all articles

On this page

  • Validation layers
  • Authoring schemas
  • OpenAPI as source
  • CI workflow example
  • Runtime (Node example)
  • Versioning schemas
  • JSON Schema vs JSONL
  • Regex in schema
  • Performance
  • Partial validation for webhooks
  • Schema versioning in CI
  • Error response quality
  • Worked example: catching a string-vs-number bug at the API gateway
  • Limitations
  • Conclusion

Related Articles

  • PHP security vulnerabilities: 10 flaws attackers exploit, and how to fix each one
  • UUID v4 vs v7: Sortable IDs in New Projects
  • URL Encoding and Decoding: A Developer Guide