</>DevTools

SCHJSON Schema Generator

Generate JSON Schema from JSON data

JSON Schema Complete Guide

JSON Schema is a standard metadata language for defining the structure, types, and constraints of JSON data. Its uses range from API request/response validation and form input checking, to OpenAPI documentation and TypeScript type generation. This tool analyzes real JSON data and auto-generates a draft 2020-12 compliant schema.

JSON Schema Key Keywords

Core Types and Keywords

KeywordDescriptionExample
typeSpecifies data type"type": "string"
requiredList of required fields"required": ["id", "name"]
propertiesDefine object fields"properties": {"id": {...}}
itemsSchema for array elements"items": {"type": "string"}
enumAllowed value list"enum": ["A", "B", "C"]
minimum/maximumNumeric range constraint"minimum": 0, "maximum": 100
patternRegex validation for strings"pattern": "^[a-z]+$"

Practical Example: API Request Validation

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "email", "age"],
  "properties": {
    "name":  { "type": "string", "minLength": 1, "maxLength": 100 },
    "email": { "type": "string", "format": "email" },
    "age":   { "type": "integer", "minimum": 0, "maximum": 150 }
  },
  "additionalProperties": false
}

Relationship with OpenAPI

OpenAPI 3.1 directly adopts JSON Schema draft 2020-12. You can paste schemas generated here directly into the requestBody.content.schema or responses.content.schema fields of your OpenAPI document. OpenAPI 3.0 uses a subset, so keywords like nullable behave differently.

Converting to TypeScript Types

Feed the generated schema into the json-schema-to-typescript npm package or quicktype.io for automatic TypeScript interface generation. Zod users can manually map to z.object() and extract types with z.infer<>.

🔗Related Tools🧰 Misc