Database Seeding
Generate hundreds of related database records for development and testing with proper foreign key relationships.
The Problem
Section titled “The Problem”Creating seed data for development requires:
- Manual work — Writing hundreds of INSERT statements
- Relationships — Maintaining foreign key consistency
- Realistic data — Making it look like real production data
- Variety — Different values, not just copy-paste
The JSSON Solution
Section titled “The JSSON Solution”users [template { id, role }
map (u) = { id = u.id uuid = "usr-" + u.id + "-" + (u.id * 1234) email = "user" + u.id + "@example.com" username = "user_" + u.id role = u.role
// Profile firstName = u.role == "admin" ? "Admin" : "User" lastName = "Number" + u.id avatar = "https://api.dicebear.com/7.x/avataaars/svg?seed=" + u.id
// Settings language = u.id % 3 == 0 ? "pt" : (u.id % 3 == 1 ? "en" : "es") theme = u.id % 2 == 0 ? "dark" : "light"
// Status isActive = true isVerified = u.id <= 50 ? true : false}
// Admin users1..5, "admin"
// Regular users6..100, "user"]{"users": [ { "id": 1, "uuid": "usr-1-1234", "email": "user1@example.com", "username": "user_1", "role": "admin", "firstName": "Admin", "lastName": "Number1", "avatar": "https://api.dicebear.com/7.x/avataaars/svg?seed=1", "language": "en", "theme": "light", "isActive": true, "isVerified": true } // ... 99 more users]}Products with Categories
Section titled “Products with Categories”products [template { id, category }
map (p) = { id = p.id sku = "PRD-" + p.category + "-" + p.id name = p.category + " Product " + p.id category = p.category
// Pricing price = (p.id * 10) + 99 currency = "BRL" discount = p.id % 5 == 0 ? 10 : 0
// Inventory stock = p.id * 10 inStock = true
// SEO slug = p.category + "-product-" + p.id}
1..30, "electronics"31..60, "clothing"61..80, "books"81..100, "home"]Orders with Relationships
Section titled “Orders with Relationships”orders [template { id, userId, productId }
map (o) = { id = o.id orderNumber = "ORD-2025-" + o.id
// Foreign keys userId = o.userId productId = o.productId
// Order details quantity = (o.id % 5) + 1 subtotal = ((o.productId * 10) + 99) * ((o.id % 5) + 1)
// Status status = o.id % 4 == 0 ? "delivered" : (o.id % 4 == 1 ? "shipped" : "pending") paymentMethod = o.id % 2 == 0 ? "credit_card" : "pix"}
// Generate 100 orders1..25, 1, 126..50, 2, 551..75, 3, 1076..100, 4, 15]Key Features
Section titled “Key Features”Ranges for Scale
Section titled “Ranges for Scale”// Generate 100 users1..100, "user"
// Generate 100 products across categories1..30, "electronics"31..60, "clothing"Foreign Keys
Section titled “Foreign Keys”// Orders reference users and productsuserId = o.userIdproductId = o.productIdVariety with Modulo
Section titled “Variety with Modulo”// Different languageslanguage = u.id % 3 == 0 ? "pt" : (u.id % 3 == 1 ? "en" : "es")
// Different payment methodspaymentMethod = o.id % 2 == 0 ? "credit_card" : "pix"Benefits
Section titled “Benefits”Realistic — Varied, production-like data
Relationships — Proper foreign keys
Scalable — Generate thousands of records
Consistent — Templates ensure structure
Fast — 100 lines → 200+ records
When to Use
Section titled “When to Use”Perfect for:
- Development database seeding
- Testing with realistic data
- Demo environments
- Load testing data
Not ideal for:
- Production data
- Extremely unique records
- Complex business logic
Try It!
Section titled “Try It!”- Save to
database-seed.jsson - Run:
jsson -i database-seed.jsson - Import into your database!
What’s Next?
Section titled “What’s Next?”- Geographic Data — Millions of coordinates
- Overview — All examples
Seed your database with ease! 💾