Format an App Config JSON File
Application configuration stored in JSON needs to be readable, consistent, and error-free. This example shows a typical app config with feature flags, database settings, and third-party service endpoints. Formatting makes it easy to review config changes in pull requests and catch typos in environment values. Validating JSON syntax before deploying prevents runtime crashes from malformed config.
Example
{
"app": { "name": "MyApp", "version": "2.1.0", "environment": "production" },
"features": {
"darkMode": true,
"betaDashboard": false,
"newOnboarding": true
},
"database": {
"host": "db.example.com",
"port": 5432,
"name": "myapp_prod"
},
"services": {
"emailProvider": "sendgrid",
"analyticsEnabled": true
}
}FAQ
- Should I store secrets in JSON config files?
- No. Passwords, API keys, and tokens should live in environment variables or a secrets manager, not in config files that are often committed to version control.
- What is feature flagging in config?
- Feature flags are boolean values in config that enable or disable features without code deploys, making it safe to roll out changes gradually or roll back instantly.
- Can I use environment-specific config files?
- Yes. A common pattern is to have config.json, config.staging.json, and config.production.json, merging the appropriate file at startup based on the NODE_ENV variable.
Related Examples
Validate a package.json File
A malformed package.json stops npm and yarn in their tracks with cryptic parse e...
Format a tsconfig.json FileTypeScript configuration files use JSON with comments (JSONC) which some tools r...
Format an ESLint Config FileESLint config files can grow complex with extended configs, custom rules, and pe...