Developer & Data

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.

By EverySolve Editorial Team • Published: • Last updated: • 5 min read

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 to object, array, string, number, integer, boolean, or null.
  • required: An array of property names that must be present on the object. If any key in required is missing, validation fails immediately.
  • additionalProperties: false: Rejects unexpected or misspelled fields (for example, if a client accidentally sends priec instead of price).
  • 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

  1. Open the EverySolve JSON Schema Validator.
  2. Paste your JSON Schema definition into the Schema editor and your JSON Instance payload into the Data editor.
  3. Click Validate to inspect field-by-field errors—including exact property paths (such as /price or /sku) and which constraint failed.
  4. 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)
About the EverySolve Editorial Team & Technical Verification:

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.

Editorial & Privacy Architecture → Spot an error? Suggest a correction →

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

Related Guides & Tutorials

← Back to All Guides Explore All Tools →