JSON to .env
Turn a nested JSON config into a flat .env file. Nested objects are flattened into joined keys, names can be uppercased into the conventional UPPER_SNAKE_CASE, arrays are kept as a JSON string or expanded into indexed keys, and values containing spaces or special characters are quoted so dotenv parses them correctly. Set an optional prefix and the output regenerates live. Everything runs in your browser.
How to use the JSON to .env
Paste a JSON object whose top level is key/value pairs (not a bare array). Nested objects are flattened by joining keys with your chosen separator — so {"app":{"port":8080}} becomes APP_PORT=8080. Pick the separator your tooling expects: a single underscore is the common default, double underscore (__) is what .NET and some config libraries use to denote nesting, and a dot suits frameworks that read dotted keys. Uppercasing follows the widespread convention that environment variables are upper snake case.
Arrays have two sensible treatments: keep the whole array as a JSON string on one key (compact, and easy to parse back), or expand it into indexed keys like FEATURES_0, FEATURES_1. Value quoting defaults to when needed — values with spaces, #, quotes, or other characters that dotenv would mis-parse get wrapped in double quotes with proper escaping, while clean values stay bare. Add a prefix to namespace every key. Copy the result into a .env file.
JSON config and the dotenv format
Many applications keep configuration as JSON during development but expect environment variables in production — the twelve-factor approach, where config lives in the environment rather than in files baked into the build. The .env file is the bridge: a simple list of KEY=value lines that tools like dotenv, Docker Compose, and most platform dashboards read to populate the environment. Converting a JSON config into that format by hand is fiddly, especially once the JSON nests.
The core problem is that JSON is hierarchical and .env is flat. Environment variables have no concept of nesting, so a structure like {"database":{"host":"…","port":5432}} must be flattened into distinct keys. The near-universal convention is to join the path with a separator and uppercase it, giving DATABASE_HOST and DATABASE_PORT. Some ecosystems standardise on a double underscore to make the nesting unambiguous and reversible — ASP.NET Core, for instance, maps Logging__LogLevel__Default back to a nested configuration section. Arrays are the other wrinkle: there's no native array in an env file, so you either serialise the array as JSON text on a single key or fan it out into numbered keys.
Quoting is where correctness bites. The dotenv format treats an unquoted # as the start of a comment and is whitespace-sensitive, so a value like change me or https://x#y must be quoted to survive a round-trip. Generating the file programmatically applies these rules consistently, which is safer than editing by hand. Note that an .env file frequently holds secrets — database passwords, API keys — so keep it out of version control and treat the generated output as sensitive.
Common use cases
- Config migration. Convert a JSON settings file into the .env variables a deployment expects.
- Twelve-factor apps. Move hierarchical config into flat environment variables for containerised deploys.
- CI and Docker. Produce an env file from JSON to feed Docker Compose or a pipeline.
- Onboarding. Hand a teammate a ready .env derived from an example JSON config.