API testing, UI prototyping, load testing और contract-driven development के लिए JSON Schema से realistic fake JSON data बनाएं।
स्टेप 1 – JSON Schema दें
- Left editor में schema paste करें या file/URL/sample से import करें।
- जहाँ संभव हो, real API schema से शुरू करें ताकि mock data production के करीब रहे।
स्टेप 2 – Schema को mock-friendly बनाएं
- Unsupported keywords से बचें जैसे
$ref, dependencies, और conditional schemas (if/then/else). - यदि आपकी schema में
$ref, हो, तो ऐसे tool से Mock Generator खोलने की कोशिश करें जो schemas को preload और dereference करता हो (उदाहरण: code→schema pages पर “Mock Data Generate करें”). - Schema को types, properties, required, items, formats और constraints पर focused रखें।
स्टेप 3 – Generation settings configure करें
- Realistic names, addresses और phone numbers के लिए locale चुनें।
- Reproducible mock data के लिए seed set करें (tests/snapshots के लिए बढ़िया)।
- Batch size, array count, number distributions और optional-field probability adjust करें।
- Validation और UI error handling test करने के लिए missing/dirty data simulation use करें।
स्टेप 4 – Output generate करें और review करें
- Schema constraints के अनुसार output बनाने के लिए “Mock Data Generate करें” क्लिक करें।
- यदि values off लगें, तो schema tight करें (formats, enums, min/max) और regenerate करें।
स्टेप 5 – Tests और generators में mock data उपयोग करें
- JSON copy/download करें और unit/integration tests के लिए fixtures के रूप में उपयोग करें।
- Generated JSON को code generators (TypeScript/Java/etc.) में feed करके matching DTOs बनाएं।
JSON Schema features के बारे में महत्वपूर्ण नोट
- जो schemas
$ref, dependencies, या if/then/else पर निर्भर हों, उन्हें mock generation से पहले simplify या dereference करना पड़ सकता है। - Schema validators drafts और keywords को अलग-अलग तरीके से interpret करते हैं; strict contract testing के लिए CI में full validator उपयोग करें।
उदाहरण: JSON Schema → mock JSON
// JSON Schema (input)
{
"type": "object",
"properties": {
"id": { "type": "string", "format": "uuid" },
"email": { "type": "string", "format": "email" },
"active": { "type": "boolean" },
"createdAt": { "type": "string", "format": "date-time" }
},
"required": ["id", "email", "active", "createdAt"]
}
// Mock JSON (output example)
{
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"email": "[email protected]",
"active": true,
"createdAt": "2024-03-01T10:15:00.000Z"
}