Here's a concise cheatsheet for JSON Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/schema.json",
"title": "Schema Title",
"description": "Schema description",
"type": "object"
}
{
"type": "object",
"properties": {
"reasoning": {
"type": "string"
},
"label": {
"type": "string",
"enum": ["yes", "no"]
}
},
"required": [
"reasoning",
"label"
]
}
"type": "string"
"type": "number"
"type": "integer"
"type": "boolean"
"type": "object"
"type": "array"
"type": "null"
{
"type": "string",
"minLength": 2,
"maxLength": 50,
"pattern": "^[A-Za-z]+$",
"format": "email"
}
{
"type": "number",
"minimum": 0,
"maximum": 100,
"exclusiveMinimum": true,
"multipleOf": 5
}
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name"],
"additionalProperties": false
}
{
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"maxItems": 5,
"uniqueItems": true
}
{
"allOf": [{ ... }, { ... }],
"anyOf": [{ ... }, { ... }],
"oneOf": [{ ... }, { ... }],
"not": { ... }
}
{
"if": { "properties": { "country": { "const": "US" } } },
"then": { "properties": { "postal_code": { "pattern": "^[0-9]{5}(-[0-9]{4})?$" } } },
"else": { "properties": { "postal_code": { "type": "string" } } }
}
{
"$defs": {
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
}
},
"properties": {
"billing_address": { "$ref": "#/$defs/address" },
"shipping_address": { "$ref": "#/$defs/address" }
}
}
This cheatsheet covers the most commonly used features of JSON Schema. It includes basic structure, data types, constraints for strings and numbers, object and array definitions, schema combinations, conditional schemas, and reusable definitions[1][2].
Citations: [1] https://json-schema.org/understanding-json-schema [2] https://github.com/CyberT33N/JSON-Schema-cheat-sheet