Faker.js Mock Factory Generator
Paste a sample JSON object and get a @faker-js/faker factory function. Field names and value shapes choose the faker call, and nested objects and arrays are handled.
Use the tool
Why this tool exists
Tests, stories and demo screens need realistic data, not the same fixture copied everywhere. Writing a faker factory for an object with twenty fields means looking up the right call for each one: an email, a UUID, a date, a URL, a person's name. It is dull work and easy to leave half done.
This tool inspects a real example and guesses the match from the field name and the value, so email becomes an email address and createdAt becomes a date. Nested objects and arrays become nested factories. The guesses are heuristics, so check the result and adjust calls where your domain needs something specific. You can set the locale and the number of items. It runs in your browser, so your sample data is not uploaded.
How to use it
- Paste a sample JSON object that shows the shape of your data.
- Choose the faker locale and how many items the factory should create.
- Read the generated factory function and check each faker call.
- Copy it into your tests or storybook files and install @faker-js/faker.
Frequently asked questions
How does it choose the faker call?
It looks at the field name first, such as email, id, url or createdAt, then at the value type. Anything it cannot place falls back to a generic call for that type, which you can replace.
Are the results deterministic?
Not by default, because faker returns random values. For stable tests, set a seed with faker.seed in your own code before calling the factory.
Do I need a package installed?
Yes. The generated code imports from @faker-js/faker, so install it as a development dependency. Check the faker version, since some method names changed between major releases.