Advanced Patterns
JSSON isn’t just for simple key-value pairs. Its features can be combined to solve complex configuration challenges. Here are some advanced patterns to supercharge your workflow.
🧪 Test Data Generation
Section titled “🧪 Test Data Generation”Need to generate thousands of records for load testing? JSSON’s ranges and string concatenation make it trivial.
Generating Dates
Section titled “Generating Dates”Combine numeric ranges with string concatenation to generate calendar dates:
test_data [template { date, event }
map (row) = { date = "2025-01-" + row.day event = "Login Attempt" status = "Success"}
// Generate dates from 1 to 311..31]{"test_data": [ { "date": "2025-01-1", "event": "Login Attempt", "status": "Success" }, // ... up to 31 { "date": "2025-01-31", "event": "Login Attempt", "status": "Success" }]}Generating User Accounts
Section titled “Generating User Accounts”Create realistic user profiles by zipping ranges and using templates:
users [template { id, department }
map (u) = { id = u.id username = "user_" + u.id email = "user_" + u.id + "@company.com" dept = u.department role = "employee"}
// Generate 5 users for Engineering100..104, Engineering
// Generate 5 users for Sales200..204, Sales]{"users": [ { "id": 100, "username": "user_100", "email": "user_100@company.com", "dept": "Engineering", "role": "employee" }, // ... { "id": 204, "username": "user_204", "email": "user_204@company.com", "dept": "Sales", "role": "employee" }]}🌍 Environment Management
Section titled “🌍 Environment Management”Manage multiple environments (Dev, Staging, Prod) cleanly using the Base + Overlay pattern with include.
1. Base Configuration (base.jsson)
Section titled “1. Base Configuration (base.jsson)”Define the common settings shared across all environments.
app { name = "MyApp" version = "1.0.0" retry_attempts = 3}
database { driver = "postgres" pool_size = 10}2. Environment Overlays (prod.jsson)
Section titled “2. Environment Overlays (prod.jsson)”Include the base config and override only what changes.
include "base.jsson"
// Override database settings for productiondatabase { host = "prod-db.aws.com" pool_size = 100 // Higher pool size for prod}
// Add prod-specific settingslogging { level = "error" format = "json"}Why this works: JSSON’s
includemerges the included file into the current scope. If you redefine a key (likedatabase), JSSON merges the new properties into the existing object, allowing for granular overrides.
🏷️ Dynamic Resource Naming
Section titled “🏷️ Dynamic Resource Naming”Enforce naming conventions automatically using the map clause. This ensures consistency across your infrastructure configuration.
resources [template { name, type, region }
map (res) = { // Auto-generate standardized ID: type-name-region id = res.type + "-" + res.name + "-" + res.region
// Pass through original fields name = res.name type = res.type region = res.region
// Add default tags tags { managed_by = "jsson" env = "production" }}
"web-server", ec2, "us-east-1""db-primary", rds, "us-west-2""cache-cluster", redis, "eu-central-1"]{"resources": [ { "id": "ec2-web-server-us-east-1", "name": "web-server", "type": "ec2", "region": "us-east-1", "tags": { "managed_by": "jsson", "env": "production" } }, { "id": "rds-db-primary-us-west-2", "name": "db-primary", "type": "rds", "region": "us-west-2", "tags": { "managed_by": "jsson", "env": "production" } }, { "id": "redis-cache-cluster-eu-central-1", "name": "cache-cluster", "type": "redis", "region": "eu-central-1", "tags": { "managed_by": "jsson", "env": "production" } }]}🔢 Matrix Generation
Section titled “🔢 Matrix Generation”Need to generate a matrix of configurations? Use nested templates or simple multiplication logic.
// Generating a grid of coordinatesgrid [template { x, y }
// This is a simple way to visualize it,// though JSSON doesn't have a 'cross-product' operator yet,// you can list ranges explicitly for simple grids.
1..3, 11..3, 21..3, 3]{"grid": [ { "x": 1, "y": 1 }, { "x": 2, "y": 1 }, { "x": 3, "y": 1 }, { "x": 1, "y": 2 }, { "x": 2, "y": 2 }, { "x": 3, "y": 2 }, { "x": 1, "y": 3 }, { "x": 2, "y": 3 }, { "x": 3, "y": 3 }]}