Lección 8

JSON Schema Basics en español

Guía en español para json json schema basics: Describe and validate document shape with types, required fields, and constraints.

Este contenido todavía no está disponible en español. Se muestra la versión en English mientras completamos la localización.

JSON Schema is a vocabulary for annotating JSON documents with rules: which properties exist, their types, and value constraints. Teams use it to validate API payloads, config files, and generated data.

A minimal schema

This schema describes an object with a required string name and optional number age:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  },
  "required": ["name"],
  "additionalProperties": false
}

Valid instance:

{ "name": "Ada", "age": 30 }

Invalid: missing name, wrong type, or extra unknown keys when additionalProperties is false.

Core keywords

KeywordPurpose
typestring, number, integer, boolean, array, object, null
propertiesShape of object fields
requiredMandatory property names
itemsSchema for each array element
enumAllowed literal values
minLength / maxLengthString bounds

Why schemas matter

  • Contracts between frontend and backend teams
  • Automated validation in CI before deploy
  • Documentation that stays machine-readable
  • OpenAPI often embeds or references JSON Schema for request bodies

Validation workflow

  1. Author or generate a schema for your expected payload.
  2. Run a validator (library or tool) against incoming JSON.
  3. Fix data or schema when real-world edge cases appear—schemas evolve like code.

Schemas do not replace understanding JSON syntax from earlier lessons—they sit on top, describing allowed structure once JSON is already parseable.

Volver al resumen del curso