Gumawa ng realistic fake JSON data mula sa JSON Schema para sa API testing, UI prototyping, load testing, at contract-driven development.
Hakbang 1 – Magbigay ng JSON Schema
- I-paste ang schema sa kaliwang editor, o mag-import mula sa file/URL/sample.
- Magsimula sa totoong API schema kung posible para mas malapit sa production ang mock data.
Hakbang 2 – Gawing mock-friendly ang schema
- Iwasan ang mga hindi suportadong keywords tulad ng
$ref, dependencies, at conditional schemas (if/then/else). - Kung gumagamit ang schema mo ng
$ref, subukang buksan ang Mock Generator mula sa tool na nagpe-prefill at nagde-dereference ng schemas (halimbawa “Gumawa ng Mock Data” sa code→schema pages). - Panatilihing nakatuon ang schema sa types, properties, required, items, formats, at constraints.
Hakbang 3 – I-configure ang generation settings
- Pumili ng locale para sa realistic names, addresses, at phone numbers.
- Magtakda ng seed para sa reproducible mock data (maganda para sa tests at snapshots).
- Ayusin ang batch size, array count, number distributions, at optional-field probability.
- Gamitin ang missing/dirty data simulation para subukan ang validation at UI error handling.
Hakbang 4 – Gumawa at suriin ang output
- I-click ang “Gumawa ng Mock Data” para gumawa ng output na sumusunod sa schema constraints mo.
- Kung may kakaibang values, higpitan ang schema (formats, enums, min/max) at i-regenerate.
Hakbang 5 – Gamitin ang mock data sa tests at generators
- Kopyahin o i-download ang JSON at gamitin bilang fixtures para sa unit/integration tests.
- I-feed ang generated JSON sa code generators (TypeScript/Java/etc.) para gumawa ng matching DTOs.
Mahalagang paalala tungkol sa JSON Schema features
- Ang schemas na umaasa sa
$ref, dependencies, o if/then/else ay kailangang i-simplify o i-dereference bago mag-mock generation. - Magkakaiba ang schema validators sa interpretasyon ng drafts at keywords; gumamit ng full validator sa CI para sa striktong contract testing.
Halimbawa: 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"
}