Skip to main content

Guides Overview

Learn common patterns and best practices for DataGeneration.

How-To Guides

Step-by-step guides for specific tasks:

Patterns

Learn how to handle advanced scenarios:

Best Practices

Use Seeds for Reproducibility

Generation gen = DslDataGenerator.create()
.withSeed(123L)
.fromJsonString(dsl)
.generate();

Using seeds ensures the same data is generated every time, perfect for testing.

Enable Memory Optimization for Large Datasets

For datasets with more than 100,000 items, enable memory optimization:

Generation gen = DslDataGenerator.create()
.withMemoryOptimization()
.fromJsonString(dsl)
.generate();

Use Sequential References for Even Distribution

When you want balanced relationships (e.g., equal employees per team):

{
"teamId": {
"ref": "teams[*].id",
"sequential": true
}
}

Leverage Weighted Choices for Realistic Data

Use weights to match real-world probability distributions:

{
"status": {
"gen": "choice",
"options": ["active", "inactive", "pending"],
"weights": [70, 20, 10]
}
}

Filter References to Enforce Business Rules

Exclude specific values from references:

{
"userId": {
"ref": "users[*].id",
"filter": [{"ref": "bannedUser.id"}]
}
}

Use Conditional References for Field-Based Filtering

Filter collections by field values before referencing:

{
"orders": {
"count": 50,
"item": {
"userId": {"ref": "users[status='active' and age>=21].id"},
"productId": {"ref": "products[stock>0].id"}
}
}
}

Use Range References for Segmented Data

Reference specific subsets by index:

{
"regionalManagers": {
"count": 4,
"item": {
"managedEmployeeId": {"ref": "employees[0:4].id"}
}
}
}

Common Patterns

User-Order Relationship

{
"users": {
"count": 5,
"item": {
"id": {"gen": "uuid"},
"name": {"gen": "name.fullName"}
}
},
"orders": {
"count": 20,
"item": {
"id": {"gen": "uuid"},
"userId": {"ref": "users[*].id"},
"total": {"gen": "float", "min": 10, "max": 1000, "decimals": 2}
}
}
}

Hierarchical Data

{
"departments": {
"count": 3,
"item": {
"id": {"gen": "uuid"},
"name": {"gen": "company.industry"}
}
},
"teams": {
"count": 9,
"item": {
"id": {"gen": "uuid"},
"name": {"gen": "lorem.word"},
"departmentId": {"ref": "departments[*].id", "sequential": true}
}
},
"employees": {
"count": 30,
"item": {
"id": {"gen": "uuid"},
"name": {"gen": "name.fullName"},
"teamId": {"ref": "teams[*].id"}
}
}
}

Admin User Pattern

{
"users": {
"count": 10,
"item": {
"id": {"gen": "uuid"},
"email": {"gen": "internet.emailAddress"},
"role": {"gen": "choice", "options": ["admin", "user"], "weights": [10, 90]}
},
"pick": {
"admin": 0
}
},
"auditLogs": {
"count": 50,
"item": {
"id": {"gen": "uuid"},
"userId": {
"ref": "users[*].id",
"filter": [{"ref": "admin.id"}]
},
"action": {"gen": "lorem.word"}
}
}
}

Next Steps