How to generate mock json for api development and prototyping
- Step 1Define the API response schema — Based on the agreed API contract or OpenAPI spec, describe the response shape as a JSON example object. Include all fields — required and optional — for a complete mock.
- Step 2Generate mock responses — Generate a single-object response for detail endpoints (GET /users/:id) and a 10-20 item array for list endpoints (GET /users). Download as JSON files.
- Step 3Serve mocks with json-server or MSW — Use json-server (npx json-server --watch db.json) to serve the generated mock data as a REST API on localhost. Or use MSW to intercept fetch calls in the browser and return mock responses.
- Step 4Replace mocks with real API when ready — Once the real API is available, remove the MSW handlers or switch the base URL from the json-server local address to the real API. No front-end code changes should be needed if the real API matches the agreed contract.
Frequently asked questions
What is the quickest way to set up a mock REST API with the generated JSON?+
Use json-server: npm install -g json-server. Create db.json with your generated data: { 'users': [...generatedUsers], 'orders': [...generatedOrders] }. Run npx json-server db.json. You get full REST endpoints: GET /users, GET /users/1, POST /users, etc., all reading from and writing to db.json.
How do I keep mock data in sync with the real API as the contract evolves?+
Maintain mock data in separate schema definition files. When the API contract changes, regenerate the mock data from the updated schema. The separation of mock data definition from generated output makes regeneration quick.
Is the prototype data transmitted to JAD Apps?+
No. Mock generation runs entirely in your browser. API contract schemas and prototype response data are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.