Generate mock data with a JSON Schema faker
This JSON Schema faker reads a schema and produces JSON documents that conform to it. Instead of hand-writing fixtures, you describe the shape once and let the generator fill in integers within minimum/maximum, strings that match format and pattern, values from enum, and arrays that respect minItems and uniqueItems.
It is built on the json-schema-faker library, which understands the common draft-07 through 2020-12 keywords. The output is plain JSON you can paste into a test, a Postman collection, a Storybook story or a seed script.
What is a JSON Schema faker for?
A schema tells you what is allowed; a faker shows you what that looks like. That makes it useful in a few specific situations:
- Front-end work before the API exists. Generate a list of users or orders and build the UI against realistic data.
- Contract tests. Feed generated payloads to your endpoint to check that everything the schema allows is really accepted.
- Reviewing a schema. If a sample looks wrong, such as a negative age or an empty array, your schema is missing a constraint.
Example
Input schema:
{
"type": "object",
"required": ["id", "email"],
"properties": {
"id": { "type": "integer", "minimum": 1, "maximum": 999 },
"email": { "type": "string", "format": "email" },
"plan": { "enum": ["free", "pro"] },
"active": { "type": "boolean" }
}
}
Output with seed 42 and optional properties filled:
{
"id": 601,
"email": "dave852@demo.net",
"plan": "free",
"active": false
}
Run it again with the same seed and you get exactly the same document, which keeps snapshot tests stable.
Options explained
- Number of samples: 1 returns a single object; 2 to 100 return an array of independent samples generated from the same seed sequence.
- Always fill optional properties: when on, every property in
propertiesis generated, not only those inrequired. Turn it off to test how your code handles missing optional fields. - Seed: leave it empty for a fresh random seed on every run. The status line shows the seed that was used, so you can copy it into the field to reproduce a sample you liked.
- Indent: 2 spaces, 4 spaces or tabs for the output.
If a property has a default, that value is used instead of a random one, which is handy for fields like "currency": "USD" that should not vary.
Edge cases and tips
- Strings without a format come out as short random text, and can even be empty. Add
minLength,format,patternor anenumwhen you need realistic values. - Remote
$refURLs are not fetched and stop generation with an "Unresolved $ref" error. Keep definitions inside the schema under$defsordefinitions. - Contradictory schemas, such as
"minimum": 10with"maximum": 1, cannot be satisfied. The faker still returns numbers, but they break the schema, so check suspicious output with the JSON Schema validator.
Related tools
No schema yet? Infer one from an example document with JSON to JSON Schema. Need types rather than data? Turn the same schema into interfaces with JSON Schema to TypeScript.
Privacy
Generation happens locally in your browser. Your schema is never sent to a server, so internal data models stay private.