مولد JSON Schema من عينة JSON
نقطة بداية سريعة لتوثيق API أو التحقق من البيانات، تعدل بعدها القيود حسب حاجتك.
جارٍ تحميل الأداة…
المعالجة والخصوصية: تُحسب النتيجة داخل متصفحك ولا تُرسل بياناتك إلى أي خادم.
طريقة الاستخدام
- أدخل نص JSON واسم النوع الرئيسي.
- تظهر النتيجة فورًا وتتحدّث مع كل تعديل.
- انسخ النتيجة، أو انسخ رابطًا يحفظ القيم نفسها لمشاركتها.
طريقة الحساب
integer للأعداد الصحيحة وnumber للكسرية وstring وboolean، وarray مع items، وobject مع properties. المفاتيح الموجودة في كل عناصر المصفوفة تدخل في required، والقيمة null تضيف "null" إلى type، والقيم المختلطة تكتب {} أي تقبل أي قيمة.
مثال
المدخلات: اسم النوع الرئيسي = Root. النتيجة: الكود الناتج: { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Root", "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "email": { "type": "string" }, "is_active": { "type": "boolean" }, "balance": { "type": "number" }, "tags": { "type": "array", "items": { "type": "string" } }, "address": { "type": "object", "properties": { "city": { "type": "string" }, "postal_code": { "type": "string" } }, "required": [ "city", "postal_code" ] }, "orders": { "type": "array", "items": { "type": "object", "properties": { "order_id": { "type": "string" }, "total": { "type": "number" }, "coupon": { "type": [ "string", "null" ] } }, "required": [ "order_id", "total", "coupon" ] } } }, "required": [ "id", "name", "email", "is_active", "balance", "tags", "address", "orders" ] }، عدد الأنواع: 3، عدد الحقول: 13.
{
"id": 1024,
"name": "Sara Ahmed",
"email": "sara@example.com",
"is_active": true,
"balance": 1520.75,
"tags": ["vip", "riyadh"],
"address": { "city": "Riyadh", "postal_code": "12211" },
"orders": [
{ "order_id": "A-1", "total": 99.5, "coupon": "EID10" },
{ "order_id": "A-2", "total": 120, "coupon": null }
]
}{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Root",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"is_active": {
"type": "boolean"
},
"balance": {
"type": "number"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"address": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"postal_code": {
"type": "string"
}
},
"required": [
"city",
"postal_code"
]
},
"orders": {
"type": "array",
"items": {
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"total": {
"type": "number"
},
"coupon": {
"type": [
"string",
"null"
]
}
},
"required": [
"order_id",
"total",
"coupon"
]
}
}
},
"required": [
"id",
"name",
"email",
"is_active",
"balance",
"tags",
"address",
"orders"
]
}الحدود والملاحظات
- لا يضيف قيودا مثل الطول الأدنى أو format أو enum، فأضفها يدويا.
- الكائنات المتداخلة تكتب داخل المخطط مباشرة دون $defs.
أسئلة شائعة عن هذه الأداة
ما الفرق بين integer وnumber؟
integer يقبل الأعداد الصحيحة فقط، وnumber يقبل أي رقم. إذا ظهر رقم كسري في أي عنصر يصبح الحقل number.
كيف يحدد المولد قائمة required؟
المفتاح الموجود في كل عناصر المصفوفة يعد مطلوبا حتى لو كانت قيمته null، والغائب عن بعضها لا يدخل القائمة.
هل يعمل المخطط مع مكتبة Ajv؟
نعم، استخدم Ajv2020 لأن المخطط يعلن draft 2020-12 في الحقل $schema.
