mock-datatestinggojavascriptpython

Random JSON Generator — Create Mock Data for Testing and Development

·8 min read

Why Generate Mock JSON Data?

Realistic mock data makes your tests more trustworthy, your demos more convincing, and your development workflow faster. Hardcoded test data quickly becomes stale, doesn't cover edge cases, and slows you down when APIs or schemas change. Random data generation solves all of this by producing varied, realistic, structurally correct records on demand.

Common use cases:

Use caseWhy mock data helps
UI prototypingSee how layouts look with realistic names, long text, edge values
Database seedingPopulate a dev DB with diverse records for manual testing
Unit / integration testsGenerate random inputs to catch edge cases automatically
Load testingCreate thousands of unique records to stress-test APIs and queues
Postman / Insomnia collectionsGenerate example request/response payloads
API documentationShow realistic sample responses instead of placeholder text

JavaScript — Faker.js

Faker.js (@faker-js/faker) is the most popular mock data library in the JavaScript ecosystem. It covers names, emails, addresses, dates, UUIDs, credit cards, company names, lorem ipsum, and much more.

javascript
// npm install @faker-js/faker
import { faker } from "@faker-js/faker";

function randomUser() {
  return {
    id:        faker.string.uuid(),
    name:      faker.person.fullName(),
    email:     faker.internet.email(),
    age:       faker.number.int({ min: 18, max: 80 }),
    city:      faker.location.city(),
    country:   faker.location.countryCode("alpha-2"),
    score:     faker.number.float({ min: 1, max: 10, fractionDigits: 2 }),
    role:      faker.helpers.arrayElement(["admin", "editor", "viewer"]),
    createdAt: faker.date.past({ years: 2 }).toISOString(),
    avatar:    faker.image.avatar(),
  };
}

// Generate 1000 records
const users = Array.from({ length: 1000 }, randomUser);
console.log(JSON.stringify(users, null, 2));

Seeded output (reproducible tests):

javascript
faker.seed(42); // always produces the same sequence
const user = randomUser();
// same output every run — perfect for snapshot tests

Locale support:

javascript
import { faker } from "@faker-js/faker";
import { fakerDE as faker } from "@faker-js/faker"; // German names/addresses
import { fakerJA as faker } from "@faker-js/faker"; // Japanese locale

Go — gofakeit

gofakeit is the Go equivalent of Faker — comprehensive, zero-dependency, and fast enough for generating millions of records in tests.

go
// go get github.com/brianvoe/gofakeit/v6
package main

import (
    "encoding/json"
    "fmt"
    "math"
    "os"

    "github.com/brianvoe/gofakeit/v6"
)

type User struct {
    ID        string   `json:"id"`
    Name      string   `json:"name"`
    Email     string   `json:"email"`
    Age       int      `json:"age"`
    City      string   `json:"city"`
    Country   string   `json:"country"`
    Score     float64  `json:"score"`
    Role      string   `json:"role"`
    Tags      []string `json:"tags"`
    CreatedAt string   `json:"createdAt"`
}

func randomUser() User {
    roles := []string{"admin", "editor", "viewer"}
    return User{
        ID:        gofakeit.UUID(),
        Name:      gofakeit.Name(),
        Email:     gofakeit.Email(),
        Age:       gofakeit.Number(18, 80),
        City:      gofakeit.City(),
        Country:   gofakeit.Country(),
        Score:     math.Round(gofakeit.Float64Range(1, 10)*100) / 100,
        Role:      roles[gofakeit.Number(0, 2)],
        Tags:      []string{gofakeit.HackerNoun(), gofakeit.HackerNoun()},
        CreatedAt: gofakeit.DateRange(
            // two years ago to now
            gofakeit.Date().Add(-2*365*24*3600*1e9),
            gofakeit.Date(),
        ).Format("2006-01-02T15:04:05Z"),
    }
}

func main() {
    gofakeit.Seed(42) // remove for random output each run

    users := make([]User, 1000)
    for i := range users {
        users[i] = randomUser()
    }
    data, _ := json.MarshalIndent(users, "", "  ")
    os.WriteFile("seed.json", data, 0644)
    fmt.Printf("Generated %d users → seed.json\n", len(users))
}

Python — Faker

python
# pip install faker
from faker import Faker
import json
import random

fake = Faker()
Faker.seed(42)   # reproducible
random.seed(42)

def random_user():
    return {
        "id":        str(fake.uuid4()),
        "name":      fake.name(),
        "email":     fake.email(),
        "age":       random.randint(18, 80),
        "city":      fake.city(),
        "country":   fake.country_code(representation="alpha-2"),
        "score":     round(random.uniform(1, 10), 2),
        "role":      random.choice(["admin", "editor", "viewer"]),
        "tags":      [fake.word(), fake.word()],
        "createdAt": fake.date_time_this_decade().isoformat(),
    }

# Generate 1000 records and write to file
users = [random_user() for _ in range(1000)]
with open("seed.json", "w") as f:
    json.dump(users, f, indent=2, default=str)
print(f"Generated {len(users)} users → seed.json")

Multiple locales:

python
from faker import Faker
fake_de = Faker("de_DE")  # German
fake_ja = Faker("ja_JP")  # Japanese
fake_hi = Faker("hi_IN")  # Hindi

JSON Schema-Driven Generation

If you already have a JSON Schema, you can generate data directly from it using json-schema-faker (JS) or hypothesis-jsonschema (Python) — no manual field mapping needed.

javascript
// npm install json-schema-faker
import jsf from "json-schema-faker";

const schema = {
  type: "object",
  properties: {
    id:    { type: "string", format: "uuid" },
    name:  { type: "string", minLength: 2, maxLength: 40 },
    age:   { type: "integer", minimum: 18, maximum: 80 },
    email: { type: "string", format: "email" },
    role:  { type: "string", enum: ["admin", "editor", "viewer"] },
  },
  required: ["id", "name", "age", "email", "role"],
};

// Generate one record
const record = jsf.generate(schema);

// Generate 100 records
const records = Array.from({ length: 100 }, () => jsf.generate(schema));
python
# pip install hypothesis hypothesis-jsonschema
from hypothesis_jsonschema import from_schema
from hypothesis import given, settings
import json

schema = {
    "type": "object",
    "properties": {
        "name":  {"type": "string"},
        "age":   {"type": "integer", "minimum": 18, "maximum": 80},
        "email": {"type": "string", "format": "email"},
    },
    "required": ["name", "age", "email"],
}

@given(from_schema(schema))
@settings(max_examples=100)
def test_user_processing(user):
    # hypothesis auto-generates 100 varied user objects
    assert isinstance(user["age"], int)
    assert 18 <= user["age"] <= 80

Using Mock Data in Postman and Test Suites

Postman dynamic variables (no library needed):

json
{
  "id":    "{{$guid}}",
  "name":  "{{$randomFullName}}",
  "email": "{{$randomEmail}}",
  "age":   {{$randomInt}}
}

Jest snapshot test with seeded data:

javascript
import { faker } from "@faker-js/faker";

beforeAll(() => faker.seed(12345));

test("renders user card correctly", () => {
  const user = {
    id:    faker.string.uuid(),
    name:  faker.person.fullName(),
    email: faker.internet.email(),
  };
  const { container } = render(<UserCard user={user} />);
  expect(container).toMatchSnapshot();
  // snapshot is stable across runs because of faker.seed(12345)
});

Mock Data Tools Comparison

ToolLanguageSchema-drivenSeededLocalesLicense
@faker-js/fakerJS/TSNoYes60+MIT
json-schema-fakerJS/TSYesYesvia fakerMIT
gofakeitGoNoYesENMIT
FakerPythonNoYes30+MIT
hypothesis-jsonschemaPythonYesNoN/AMPL-2
MimesisPythonNoYes30+MIT

Use JSONKit's Random JSON Generator to get mock data instantly in your browser — define your schema visually, set the record count, and copy the generated JSON directly into your tests or Postman collections.

Try Random JSON Generator

Generate realistic mock JSON data with custom fields. No dependencies, runs in browser.