How to Seed a Database with JSON Data (PostgreSQL, MySQL, MongoDB)

June 19, 2026

Seeding a development database with realistic data is one of those tasks every developer does repeatedly — and wastes too much time on. This guide shows the exact commands and patterns to seed PostgreSQL, MySQL, and MongoDB using JSON or CSV data generated with Dummy JSON Generator.


Why Good Seed Data Matters

Most developers seed their dev database with 5–10 manually written records. That works for basic smoke tests, but it hides a class of bugs that only appear with realistic data volumes and variety:

  • Pagination breaks at specific counts (11, 25, 101)
  • Search queries that perform fine on 10 records grind to a halt on 10,000
  • UI components that look fine with short English names break with long names or Unicode characters
  • NULL handling bugs that only surface when optional fields are actually absent

Seeding with 1,000–10,000 realistic records catches these problems before production does.


Step 1: Generate Your Seed Data

Open Dummy JSON Generator and configure a schema that matches your actual database table. For a users table, you might use:

Field NameTypeMaps to Column
idUUIDUUID primary key
full_namefullNameVARCHAR(100)
emailemailVARCHAR(255) UNIQUE
citycityVARCHAR(100)
statusEnum: active, inactive, pendingENUM or VARCHAR
created_atdateTimeTIMESTAMP

Set the record count to 1,000–10,000 and choose your export format based on the database you're seeding. CSV is the fastest import method for all three databases — use SQL only if you need INSERT statements for a migration file.


PostgreSQL Seeding

Option A: COPY from CSV (Fastest)

PostgreSQL's COPY command is the fastest way to bulk-insert data — typically 10–50x faster than individual INSERT statements.

-- Create the table first
CREATE TABLE users (
    id UUID PRIMARY KEY,
    full_name VARCHAR(100),
    email VARCHAR(255) UNIQUE,
    city VARCHAR(100),
    status VARCHAR(20),
    created_at TIMESTAMP
);

-- Import the CSV (run in psql shell)
\COPY users (id, full_name, email, city, status, created_at)
FROM '/path/to/generated-data.csv'
CSV HEADER;

From the command line without entering the psql shell:

psql -U postgres -d mydb -c "\COPY users FROM 'data.csv' CSV HEADER"

Option B: pg_seed in Node.js

For seeding as part of a Node.js project setup:

// seed.js
import { readFileSync } from 'fs';
import pg from 'pg';

const client = new pg.Client({ connectionString: process.env.DATABASE_URL });
const users = JSON.parse(readFileSync('./seed-data/users.json', 'utf8'));

await client.connect();

for (const user of users) {
    await client.query(
        `INSERT INTO users (id, full_name, email, city, status, created_at)
         VALUES ($1, $2, $3, $4, $5, $6)
         ON CONFLICT (email) DO NOTHING`,
        [user.id, user.full_name, user.email, user.city, user.status, user.created_at]
    );
}

await client.end();
console.log(`Seeded ${users.length} users.`);

Option C: Prisma Seed

// prisma/seed.ts
import { PrismaClient } from '@prisma/client';
import users from '../seed-data/users.json';

const prisma = new PrismaClient();

async function main() {
    await prisma.user.createMany({
        data: users,
        skipDuplicates: true,
    });
    console.log(`Seeded ${users.length} users.`);
}

main().finally(() => prisma.$disconnect());

Add to package.json:

"prisma": {
    "seed": "ts-node prisma/seed.ts"
}

Run with: npx prisma db seed


MySQL Seeding

Option A: LOAD DATA INFILE from CSV

LOAD DATA INFILE '/path/to/generated-data.csv'
INTO TABLE users
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(id, full_name, email, city, status, created_at);

If you get a --secure-file-priv error, use LOCAL:

LOAD DATA LOCAL INFILE '/path/to/generated-data.csv'
INTO TABLE users ...;

Option B: Using the SQL Export Directly

mysql -u root -p mydb < generated-data.sql

MongoDB Seeding

Export as JSON from Dummy JSON Generator, then use mongoimport:

# Import JSON array
mongoimport \
  --uri "mongodb://localhost:27017/mydb" \
  --collection users \
  --file generated-data.json \
  --jsonArray

# For MongoDB Atlas
mongoimport \
  --uri "mongodb+srv://user:pass@cluster.mongodb.net/mydb" \
  --collection users \
  --file generated-data.json \
  --jsonArray

Or using Mongoose in Node.js:

import mongoose from 'mongoose';
import User from './models/User.js';
import users from './seed-data/users.json' assert { type: 'json' };

await mongoose.connect(process.env.MONGODB_URI);
await User.deleteMany({});
await User.insertMany(users);
console.log(`Seeded ${users.length} users.`);
await mongoose.disconnect();

Best Practices

Always seed in a transaction (SQL). Wrap your seed script in a transaction so a partial failure doesn't leave your database in a half-seeded state.

Use ON CONFLICT DO NOTHING. Makes your seed script idempotent — safe to re-run without duplicating data.

Keep seed data in version control. Commit your seed-data/ directory alongside your schema migrations. New team members run one command and have a full local database.

Separate seed data by environment. Use different record counts for different environments: 100 records for CI (fast tests), 10,000 for local dev (realistic), and never seed production with fake data.


Need to generate the seed data itself? Open the tool — pick your fields, set your record count, and download JSON, CSV, or SQL in under a minute.