| Правило | Правильно | Неправильно |
|---|---|---|
| Ключи в двойных кавычках | {"name": "John"} |
{name: "John"} или {'name': "John"} |
| Строки в двойных кавычках | "value" |
'value' |
| Без trailing comma | {"a": 1, "b": 2} |
{"a": 1, "b": 2,} |
| Регистрозависимость | name ≠ Name |
- |
{
"string": "text",
"number": 42,
"float": 3.14,
"exponential": 2.5e10,
"boolean": true,
"null": null
}
{
"object": {
"nested": "value"
},
"array": [1, 2, 3],
"mixed": [1, "two", true, null, {"key": "value"}]
}
| Последовательность | Символ | Пример |
|---|---|---|
\" |
" | "He said \"Hi\"" |
\\ |
\ | "C:\\Users" |
\/ |
/ | "http:\/\/example.com" |
\n |
Новая строка | "Line1\nLine2" |
\r |
Возврат каретки | "Text\r\n" |
\t |
Табуляция | "Col1\tCol2" |
\b |
Backspace | "Text\b" |
\f |
Form feed | "Page\f" |
\uXXXX |
Unicode | "\u00A9" (©) |
Запрещено:
// или /* */), после последнего элемента)undefinedNaN, Infinity012){"type": "string"} // Строка
{"type": "number"} // Число (int или float)
{"type": "integer"} // Целое число
{"type": "boolean"} // true/false
{"type": "null"} // null
{"type": "object"} // Объект
{"type": "array"} // Массив
{"type": ["string", "null"]} // Может быть string или null
{
"type": "string",
"minLength": 3,
"maxLength": 20,
"pattern": "^[A-Za-z0-9]+$",
"enum": ["option1", "option2", "option3"],
"format": "email"
}
| Формат | Описание |
|---|---|
email |
Email адрес |
uri / uri-reference |
URL |
date |
YYYY-MM-DD |
time |
HH:MM:SS |
date-time |
ISO 8601 (2025-12-10T14:30:00Z) |
uuid |
UUID |
ipv4 / ipv6 |
IP адрес |
hostname |
Имя хоста |
// Email
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
// Телефон
"pattern": "^\\+?[0-9]{10,15}$"
// URL
"pattern": "^https?://.*$"
// Дата YYYY-MM-DD
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
// Только буквы
"pattern": "^[a-zA-Z]+$"
// Буквы и цифры
"pattern": "^[a-zA-Z0-9]+$"
{
"type": "number",
"minimum": 0, // >= 0
"maximum": 100, // <= 100
"exclusiveMinimum": 0, // > 0
"exclusiveMaximum": 100, // < 100
"multipleOf": 5 // Кратно 5
}
// Возраст
{"type": "integer", "minimum": 0, "maximum": 150}
// Цена
{"type": "number", "exclusiveMinimum": 0, "multipleOf": 0.01}
// Процент
{"type": "number", "minimum": 0, "maximum": 100}
// Рейтинг
{"type": "integer", "minimum": 1, "maximum": 5}
{
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
},
"required": ["name"], // Обязательные поля
"additionalProperties": false, // Запретить доп. поля
"minProperties": 1, // Минимум свойств
"maxProperties": 10 // Максимум свойств
}
{
"type": "array",
"items": {"type": "string"}, // Все элементы - строки
"minItems": 1, // Минимум элементов
"maxItems": 10, // Максимум элементов
"uniqueItems": true // Уникальные элементы
}
{
"type": "array",
"items": [
{"type": "string"},
{"type": "number"},
{"type": "boolean"}
],
"minItems": 3,
"maxItems": 3
}
Валидный: ["John", 30, true]
// allOf - должно соответствовать ВСЕМ схемам
{
"allOf": [
{"type": "string"},
{"minLength": 5},
{"maxLength": 10}
]
}
// anyOf - хотя бы ОДНОЙ схеме
{
"anyOf": [
{"type": "string"},
{"type": "number"}
]
}
// oneOf - РОВНО ОДНОЙ схеме
{
"oneOf": [
{"type": "string"},
{"type": "number"}
]
}
// not - НЕ должно соответствовать
{
"not": {"type": "string"}
}
{
"type": "object",
"properties": {
"type": {"type": "string", "enum": ["personal", "business"]},
"companyName": {"type": "string"}
},
"if": {
"properties": {"type": {"const": "business"}}
},
"then": {
"required": ["companyName"]
}
}
Если type === "business", то companyName обязателен.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Product identifier"
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"price": {
"type": "number",
"exclusiveMinimum": 0
}
},
"required": ["id", "name", "price"],
"additionalProperties": false
}