Skip to content

Include Modules Guide

As your configurations grow, keeping everything in one file becomes messy. JSSON’s include statement lets you split your configs into logical, reusable modules. Let’s learn how! 🧩

Without includes:

// One massive 500-line config file 😰
app {
// 50 lines of app config...
}
database {
// 100 lines of database config...
}
api {
// 150 lines of API config...
}
// ... and so on

With includes:

// main.jsson - Clean and organized! 😎
include "app.jsson"
include "database.jsson"
include "api.jsson"

Much better, right?

The include statement is simple:

include "path/to/file.jsson"

That’s it! The contents of the included file are merged into your main file.

database.jsson:

database {
host = "localhost"
port = 5432
name = myapp_db
pool {
min = 2
max = 10
}
}

main.jsson:

app {
name = "My Application"
version = "1.0.0"
}
include "database.jsson"

Result (JSON):

{
"app": {
"name": "My Application",
"version": "1.0.0"
},
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp_db",
"pool": {
"min": 2,
"max": 10
}
}
}

JSSON resolves include paths relative to the file containing the include statement.

// Same directory
include "database.jsson"
// Subdirectory
include "config/database.jsson"
// Parent directory
include "../shared/common.jsson"

Here’s a recommended structure for large projects:

project/
├── config/
│ ├── main.jsson # Main entry point
│ ├── app.jsson # Application settings
│ ├── database.jsson # Database config
│ ├── api.jsson # API settings
│ └── environments/
│ ├── dev.jsson # Development overrides
│ ├── staging.jsson # Staging overrides
│ └── prod.jsson # Production overrides

main.jsson:

// Core configuration
include "app.jsson"
include "database.jsson"
include "api.jsson"
// Environment-specific (choose one)
include "environments/dev.jsson"

Let’s build a complete application configuration using modules.

app {
name = "E-Commerce Platform"
version = "2.1.0"
debug = false
features {
newCheckout = true
recommendations = true
analytics = true
}
}
database {
primary {
host = "db.example.com"
port = 5432
name = ecommerce_db
ssl = true
}
replica {
host = "db-replica.example.com"
port = 5432
readonly = true
}
pool {
min = 5
max = 20
timeout = 30000
}
}
api {
baseUrl = "https://api.example.com"
version = "v2"
timeout = 5000
endpoints {
products = "/products"
users = "/users"
orders = "/orders"
payments = "/payments"
}
rateLimit {
requests = 100
window = 60
}
}
cache {
redis {
host = "cache.example.com"
port = 6379
ttl = 3600
}
strategies {
products = aggressive
users = moderate
orders = minimal
}
}
// Main configuration file
include "app.jsson"
include "database.jsson"
include "api.jsson"
include "cache.jsson"
// Additional settings
monitoring {
enabled = true
service = datadog
apiKey = "your-api-key"
}

Now you have a clean, modular configuration that’s easy to maintain!

You can include as many files as you need:

include "app.jsson"
include "database.jsson"
include "api.jsson"
include "cache.jsson"
include "monitoring.jsson"
include "logging.jsson"

Files are processed in order, top to bottom.

Use includes to handle different environments:

app {
name = "My App"
version = "1.0.0"
}
features {
analytics = true
logging = true
}
include "base.jsson"
app {
debug = true
}
database {
host = localhost
port = 5432
}
include "base.jsson"
app {
debug = false
}
database {
host = "prod-db.example.com"
port = 5432
ssl = true
}

Then use the appropriate file for each environment!

Group related settings together:

config/
├── app.jsson # Application settings
├── database.jsson # All database config
├── api.jsson # API configuration
├── auth.jsson # Authentication
└── monitoring.jsson # Monitoring & logging
// Good ✅
include "database-config.jsson"
include "api-endpoints.jsson"
// Bad ❌
include "config1.jsson"
include "stuff.jsson"
// Good ✅
include "database.jsson"
include "api.jsson"
app {
name = "My App"
}
// Bad ❌
app {
name = "My App"
}
include "database.jsson" // Harder to see what's included
// Avoid this:
// main.jsson includes config.jsson
// config.jsson includes database.jsson
// database.jsson includes pool.jsson
// pool.jsson includes limits.jsson
// Keep it simple - 1-2 levels max
// Main configuration
// Includes: app, database, API, and cache settings
include "app.jsson" // Application configuration
include "database.jsson" // Database connection and pool
include "api.jsson" // External API settings
include "cache.jsson" // Redis cache configuration
config/
├── shared.jsson # Common settings
├── dev.jsson # Development (includes shared)
├── staging.jsson # Staging (includes shared)
└── prod.jsson # Production (includes shared)
config/
├── main.jsson
└── features/
├── auth.jsson
├── payments.jsson
├── notifications.jsson
└── analytics.jsson
config/
├── main.jsson
└── services/
├── database.jsson
├── cache.jsson
├── queue.jsson
└── storage.jsson
Error: include file not found: database.jsson

Solution: Check that:

  1. The file exists
  2. The path is correct (relative to the including file)
  3. The file extension is .jsson
Error: circular include detected

Solution: Don’t have files include each other:

// ❌ Bad
// a.jsson includes b.jsson
// b.jsson includes a.jsson
// ✅ Good
// main.jsson includes both a.jsson and b.jsson

Now that you can organize your configs with includes, explore more advanced features:

Happy modularizing! 🎯