دليل JSON Schema

يصف JSON Schema شكل بيانات JSON ويمكنه التحقق من المستندات تلقائيًا.

الكلمات الأساسية

type يحدد نوع القيمة. properties يعرف الحقول. required يسرد المفاتيح المطلوبة. items يصف عناصر المصفوفة.

مخطط مثال

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

enum وconst

enum يسمح بمجموعة ثابتة. const يتطلب قيمة واحدة.

{"role": {"enum": ["admin", "editor", "viewer"]}}

$ref والمخططات القابلة لإعادة الاستخدام

$ref يشير إلى تعريف آخر للحفاظ على قابلية الصيانة.

{"$defs":{"id":{"type":"integer"},"type":"object","properties":{"id":{"$ref":"#/$defs/id"}}}