How to Validate JSON Payloads Against JSON Schema Specifications
Prevent runtime API bugs by validating incoming JSON structures, required keys, data types, and regex patterns against a formal JSON Schema contract.
Knowing that a string is syntactically valid JSON only tells you that its brackets and quotes match—it does not guarantee that userId is an integer rather than null, or that email is actually present before your backend writes to a database.
JSON Schema solves this by letting you define a declarative contract—written in JSON itself—that specifies the exact structure, data types, required properties, and value constraints an incoming payload must satisfy.
Anatomy of a Practical JSON Schema
Below is a realistic JSON Schema contract for a product catalog item:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["sku", "name", "price", "inStock"],
"additionalProperties": false,
"properties": {
"sku": {
"type": "string",
"pattern": "^[A-Z]{3}-[0-9]{4}$"
},
"name": {
"type": "string",
"minLength": 2,
"maxLength": 120
},
"price": {
"type": "number",
"minimum": 0
},
"inStock": {
"type": "boolean"
},
"tags": {
"type": "array",
"items": { "type": "string" }
}
}
}
Key Validation Keywords Explained
type: Restricts a value toobject,array,string,number,integer,boolean, ornull.required: An array of property names that must be present on the object. If any key inrequiredis missing, validation fails immediately.additionalProperties: false: Rejects unexpected or misspelled fields (for example, if a client accidentally sendspriecinstead ofprice).minimum/maximum&minLength/maxLength: Enforces numeric bounds and string length limits.pattern: Validates strings against a regular expression (which you can test beforehand in the EverySolve Regex Tester).
Step-by-Step: Testing Payloads in EverySolve
- Open the EverySolve JSON Schema Validator.
- Paste your JSON Schema definition into the Schema editor and your JSON Instance payload into the Data editor.
- Click Validate to inspect field-by-field errors—including exact property paths (such as
/priceor/sku) and which constraint failed. - If either document fails to parse as JSON first, format and fix syntax issues with the JSON Formatter.
Standards & Technical References
- JSON Schema Validation: A Vocabulary for Structural Validation of JSON — JSON Schema Specification (Draft 2020-12 / IETF Internet-Draft) (Reference)
Examples and keywords verified against the JSON Schema Draft-07 and Draft 2020-12 core validation vocabularies. EverySolve guides are written and maintained by our engineering and editorial team to document exact formulas, file-format standards, and browser-based workflows.
Frequently Asked Questions
What is the difference between type 'number' and type 'integer' in JSON Schema?
In JSON Schema, 'number' matches any numeric value including floating-point decimals (like 19.99), whereas 'integer' only accepts whole numbers with no fractional part (like 20).
Why should I set 'additionalProperties: false' on strict API schemas?
By default, JSON Schema ignores unknown extra keys on an object. Setting 'additionalProperties: false' catches client typos (such as sending 'user_id' instead of 'userId') and prevents unexpected fields from slipping into document databases.
Are optional properties allowed when using 'required'?
Yes. Any property defined inside 'properties' that is NOT listed in the 'required' array (such as 'tags' in the example above) is optional—if omitted, the payload passes; if included, its value must match its defined type.
Related Online Tools
-
JSON Schema Validator
Validate JSON documents and schemas online with error reporting.
-
JSON Formatter & Validator
Format, validate, prettify, and minify raw JSON string data with line error highlights.
-
RegEx Tester & Debugger
Test regular expressions against target text strings instantly.
-
JSON to CSV Converter
Flatten JSON arrays and nested objects into RFC 4180 compliant CSV spreadsheet rows using dot-notation column headers.
Related Guides & Tutorials
-
How to Implement Schema.org JSON-LD Structured Data for Google Rich Results
Learn how to write, validate, and deploy Schema.org JSON-LD structured data for Articles, FAQs, Products, and Local Businesses, plus SERP pixel limits and XML sitemaps.
-
How to Decode JWT Tokens, Understand Base64URL Claims, and Verify HMAC Signatures
Inspect the 3-part RFC 7519 JSON Web Token structure, understand why Base64URL encoding is not encryption, verify HMAC-SHA256 signatures, and generate cryptographic secrets.
-
How to Format, Pretty-Print, and Debug Broken JSON Data
Turn unreadable single-line API payloads into indented JSON trees, minify payloads for production transit, and fix the 5 most common RFC 8259 syntax errors.
-
How to Test and Debug Regular Expressions (Regex) Without Backtracking Bugs
Learn practical regular expression syntax, capture groups, lookaheads, and flags, and avoid common mistakes like broken email TLDs and catastrophic backtracking.