レッスン 8

JSON Schema Basics 日本語ガイド

日本語の json json schema basics ガイド: Describe and validate document shape with types, required fields, and constraints.

このコンテンツはまだ日本語で用意されていません。ローカライズが完了するまで English 版を表示しています。

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.

実践したいときは関連する DevCove ツールを使えます。任意であり、このレッスンの必須部分ではありません。

関連ツールを開く

コース概要へ戻る