betterconfig import creates and updates many keys in one environment from a file. It understands three formats. Keys that already exist are skipped unless you pass --overwrite, and --dry-run shows what would be created and updated first.
JSON object
Every property becomes a key, with its type inferred from the value. This is exactly what export writes.
config.json
{
"checkout.enabled": true,
"api.timeoutMs": 5000,
"banner.title": "Spring sale",
"allowed_regions": ["us", "eu"],
"theme": { "accent": "green", "radius": 8 }
}
JSON array of entries
For full control, list entries with a key, a value, and optionally a type (any --type string or a type definition) and a description. Without a type, it's inferred from the value.
keys.json
[
{
"key": "checkout.enabled",
"type": "boolean",
"value": true,
"description": "Kill switch for checkout"
},
{ "key": "allowed_regions", "type": "string[]", "value": ["us", "eu"] },
{
"key": "limits",
"type": { "kind": "object", "fields": { "maxBatch": { "kind": "number" } } },
"value": { "maxBatch": 50 }
}
]
dotenv
KEY=value lines, with optional export prefixes, quotes, and comments. Files named like .env, .env.local, or prod.env are read as dotenv automatically. Anything else is read as JSON unless you pass --format dotenv.
.env
# Comments and blank lines are skipped
export API_TIMEOUT_MS=5000
BANNER_TITLE="Spring sale"
SUPPORT_EMAIL=help@example.com # trailing comments too
Every dotenv value imports as a string, so API_TIMEOUT_MSabove becomes the string "5000". Use JSON when you want numbers, booleans, or objects.
Large files and partial failures
Big files are sent in batches of 500 keys, with a short pause between batches. If some values don't match their key's type, the rest still import, the rejected keys are listed, and the command exits with code 1.
Export
betterconfig exportwrites an environment's live config as a flat, alphabetically sorted JSON object (the default) or as dotenv with --format dotenv, where non-string values are written as JSON. It prints to stdout, or to a file with --out. Because status messages go to stderr, you can pipe one environment straight into another:
# Preview, then copy prod into staging
betterconfig export --env prod | betterconfig import - --env staging --overwrite --dry-run
betterconfig export --env prod | betterconfig import - --env staging --overwrite