JSON to .env
Turn a JSON config object into .env lines — nested keys become UPPER_SNAKE with the __ separator, values quoted when needed.
Config object to environment file
Twelve-factor apps read configuration from the environment, and a .env file is how you declare it locally and in Docker. This tool serializes a JSON config object into .env lines: keys become UPPER_SNAKE_CASE, nested objects flatten with the __ double-underscore separator (the convention .NET and docker-compose understand), and values are quoted only when they contain spaces or special characters.
{ "port": 8080, "database": { "host": "db.local", "name": "app" } }
PORT=8080
DATABASE__HOST=db.local
DATABASE__NAME=appThe __ nesting convention
Flat environments can't express hierarchy, so nested config is encoded in the key. Many loaders map DATABASE__HOST back to database.host automatically — ASP.NET Core and docker-compose among them. If your framework uses a different separator (a single _, or :), adjust the generated keys to match.
Reversible
Reading an existing .env the other way? .env to JSON parses it into a JSON object — handy for inspecting or diffing configuration.
Frequently asked questions
How is nesting represented?
With a double underscore: {"database":{"host":"x"}} becomes DATABASE__HOST=x. Arrays use a numeric segment (FEATURES__0=auth). This matches how .NET and docker-compose map env keys back to nested config.
When are values quoted?
Only when necessary — a value with spaces, #, quotes or leading/trailing whitespace is wrapped in double quotes with escaping. Plain values like 8080 or true are left bare, which is how .env files are usually written.
Why are keys uppercased?
Environment variable names are conventionally UPPER_SNAKE_CASE, and many shells treat them case-sensitively. Uppercasing produces the idiomatic form; adjust if your loader expects otherwise.
What about types?
Everything becomes text — environment variables have no types. true stays the string "true"; your application parses it. null becomes an empty value.