JSON Schema Validation in API Workflows
JSON Schema validates request and response shapes before code runs — catching contract drift in CI, gateways, and documentation. A practical validation workflow for API teams.
By Vertex Solutions Editorial
Production 500s traced to quantity: "12" — string, not number. TypeScript types on server were wrong; client "worked" until a new mobile build sent strings from a form field. No runtime validator at the boundary.
JSON Schema at the door would have returned 400 Bad Request with a clear path /quantity expected number.
Quick answer
Production 500s traced to quantity: "12" — string, not number. TypeScript types on server were wrong; client "worked" until a new mobile build sent strings from a form field. No runtime validator at the boundary.
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 |
Defense in depth — not pick one.
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 — debate internally for public APIs (forward compatibility).
Craft fixtures in JSON Formatter, validate with JSON Validator.
JSON Formatting Guide, Common JSON Formatting Errors.
OpenAPI as source
Define components.schemas → generate TypeScript types (openapi-typescript) → validators (ajv).
Drift happens when code changes without spec update — CI must validate samples against spec.
CI workflow example
openapi.yamlin repo- Example files
examples/create-order.json - CI step:
ajv validate -s schema -d examples/*.json - Contract test: supertest response
.toMatchSchema()
Pretty-print failures — JSON Pretty Print CI — redact 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 for clarity.
Versioning schemas
/v1/ schemas frozen; /v2/ additive changes. Don't mutate v1 schema in breaking ways — new schema file.
UUID v4 vs v7 — format: uuid in schema.
JSON Schema vs JSONL
JSON vs JSONL — line-delimited logs need per-line schema validation in stream processors.
Regex in schema
pattern for codes — test in Regex Tester — Regex Email Truth shows format pitfalls.
Performance
Compile schemas once at startup. Large payloads — validate structure before deep business rules.
Troubleshooting
What is JSON Schema used for in APIs? JSON Schema defines expected structure — types, required fields, enums, formats — for JSON documents. Validators check incoming requests and outgoing responses against schemas before business logic or after code changes in CI.
Should I validate API requests at runtime or only in tests? Both. Runtime validation at API boundary protects production from bad clients. CI validation against fixtures catches schema regressions when code changes. Gateway validation optional middle layer.
How does JSON Schema relate to OpenAPI? OpenAPI 3.x embeds JSON Schema (with subset/dialect differences) for request/response models. Single source of truth in OpenAPI can generate schemas, docs, and validators — keep them synchronized.
Limitations
Browser-based workflows for json schema validation in api workflows depend on file size, browser memory, and how the source file was created. Very large files, password-protected inputs, or unusual encodings may fail without a desktop alternative. Always keep an original copy before batch processing.
When not to use this approach
Skip browser-only processing when compliance requires audit logs, when files exceed practical browser limits, or when you need features your browser tool does not expose (bookmarks, form fields, digital signatures). In those cases, use dedicated desktop software or an approved enterprise pipeline.
Related tools
Conclusion
Schema at boundary + fixtures in CI — types alone don't survive HTTP.
Return 400 with paths, not 500 mysteries. quantity as string dies at the door, not in accounting.
Partial validation for webhooks
Stripe-style webhooks — validate event envelope schema, defer nested object validation to handler with specific schema per event type. Fail fast on malformed envelope; typed handlers for payload.
Schema versioning in CI
schemas/v1/order.json and schemas/v2/order.json coexist — CI validates examples in examples/v1/ against matching version. Prevent v2 example validating against v1 schema falsely passing.
Error response quality
Return JSON Pointer in validation error: {"path": "/quantity", "message": "expected number"} — mobile clients highlight field. Generic "validation failed" increases support tickets.
Putting this into practice this week
Pick one workflow from this article and run it on a real task today — not a hypothetical. If the guide covers PDF export, export one document you already need for work. If it covers image naming, rename one messy folder. Knowledge retained from doing beats knowledge retained from reading.
Questions to ask before you delegate
When handing a process to a teammate or virtual assistant, ask: "What would break if you skipped step three?" If they can't answer, the process isn't documented enough. Add the missing step to your internal wiki with a link to this guide and the relevant tool page.
How this connects to the broader site
Utility-first sites win when guides and tools reinforce each other. Bookmark the tool URL alongside this article. Share the article link when onboarding someone who'll use the tool weekly — context reduces support messages asking the same formatting question twice.
Common "it worked yesterday" causes
Software updates change export defaults. Browser updates change PDF print behavior. CDN cache serves old image after you uploaded new asset. When workflows break without code changes, check version changelogs before blaming user error. First troubleshooting step: reproduce in clean browser profile with extensions disabled.
When to escalate to a specialist
Tax, legal, medical, and enterprise security topics in adjacent guides sometimes require professional advice. Articles like this explain operational literacy — not professional services. Escalate when stakes exceed convenience (court filing, audit response, M&A data room, HIPAA-covered PHI).
Quick reference checklist
Before you close the tab, confirm the basics from this guide:
- You know which tool or export path applies to your exact file type
- You've tested output on the device or platform your audience uses
- Filename, margins, or metadata won't embarrass you in a professional context
- You've linked related guides for the next step in the workflow
- Sensitive data stayed in the processing tier your policy allows (browser vs cloud)
Print or save this checklist for onboarding teammates — utility workflows fail from skipped verification, not missing features.
Related reading on this site
Browse the blog category cluster this article belongs to for deeper dives. Tool pages linked in-body are the fastest path from reading to doing. If something in the workflow still feels fuzzy, that's a signal to run one real file through the pipeline and note where friction appeared — then re-read the section that matches that step.
Final reminder
Good document and media hygiene compounds. An extra ninety seconds at export time prevents ninety minutes of rework when a client, professor, printer, or auditor sends the file back. The tools exist to make that ninety seconds painless — use them deliberately rather than hoping defaults match your stakes.
Frequently Asked Questions
Common questions answered to help you get the most from this tool.