Skip to content

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.

Need to generate thousands of records for load testing? JSSON’s ranges and string concatenation make it trivial.

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 31
1..31
]

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 Engineering
100..104, Engineering
// Generate 5 users for Sales
200..204, Sales
]

Manage multiple environments (Dev, Staging, Prod) cleanly using the Base + Overlay pattern with include.

Define the common settings shared across all environments.

base.jsson
app {
name = "MyApp"
version = "1.0.0"
retry_attempts = 3
}
database {
driver = "postgres"
pool_size = 10
}

Include the base config and override only what changes.

prod.jsson
include "base.jsson"
// Override database settings for production
database {
host = "prod-db.aws.com"
pool_size = 100 // Higher pool size for prod
}
// Add prod-specific settings
logging {
level = "error"
format = "json"
}

Why this works: JSSON’s include merges the included file into the current scope. If you redefine a key (like database), JSSON merges the new properties into the existing object, allowing for granular overrides.

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"
]

Need to generate a matrix of configurations? Use nested templates or simple multiplication logic.

// Generating a grid of coordinates
grid [
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, 1
1..3, 2
1..3, 3
]