Mock API data generator and JSON fixtures

Give frontend and integration work realistic typed responses before a production backend or stable test environment exists.

Generate JSON data →JSON format details

Model the response contract

Name fields after the API contract and select generators with matching JSON types. Use Integer or Decimal rather than numeric-looking text, Boolean for flags, Date or Datetime for timestamps and Blank % for nullable properties. Patterns and custom lists cover status codes, SKU shapes and finite enums.

Build useful response states

A happy-path list is only the beginning. Save separate schemas for active users, incomplete profiles, cancelled orders and sparse search results. Keep a fixed seed for visual regression baselines, then change the seed when exploratory testing needs fresh combinations.

JSON array or NDJSON stream?

JSON returns one array and is the natural fit for REST fixtures, browser imports and intercepted responses. NDJSON writes one object per line and is better for log ingestion, bulk endpoints and streaming consumers.

Serve the fixture locally

// Express example
import users from './fixtures/users.json' with { type: 'json' };
app.get('/api/users', (req, res) => res.json(users));

You can also return the file from Playwright route interception, a service worker, json-server or the sibling Fun API Playground.

Contract-test checklist

  • Property names and JSON types match the documented contract.
  • Nullable properties include both values and null.
  • Dates use the expected timezone and representation.
  • IDs are unique where clients use them as keys.
  • Strings include realistic long and international values.
  • Fixtures contain empty-list and partial-object variants.

Keep fixtures safe

Use generated documentation-domain emails and test-only network/payment values instead of copying real user data. Read the methodology and safety notes, then store the exported schema with the consuming test so future changes remain intentional.