JSON to .env
Flatten a JSON object into .env lines. Nested keys are joined with a separator (__ by default, the convention .NET and Spring both use), names are uppercased, and values that contain spaces, quotes or newlines are quoted and escaped so the file parses correctly.
How to convert JSON to a .env file
- Paste your JSON configuration object.
- Pick the Nested key separator.
__is what ASP.NET Core and Spring Boot expect for nested config; plain_is more readable but ambiguous if your keys already contain underscores. - Leave uppercasing on — that is the environment-variable convention on every Unix system.
- Tick Prefix with export if you plan to
sourcethe file in a shell rather than load it with a dotenv library. - Copy or download the
.env. Remember to add it to.gitignore.
How values are made safe
- Spaces, quotes,
$, backticks and backslashes trigger double-quoting with the inner characters escaped, so the shell and dotenv libraries both read the value you intended. - Newlines become
\ninside a quoted value. This is what most dotenv libraries expect for multi-line secrets such as private keys — but not all of them un-escape it, so check yours. - Empty values are written as
KEY=""rather than a bareKEY=, which some parsers read as undefined. - Arrays of scalars are comma-joined. Arrays of objects are indexed, e.g.
ITEMS__0__ID. - Characters that cannot appear in a variable name — anything outside
A-Z,0-9and_— are replaced with an underscore.
A note on secrets
This runs entirely in your browser, so pasting a config file here does not transmit it anywhere. Even so:
a .env file is usually the most sensitive file in a repository. Keep it out of version
control, and prefer your platform's secret manager over a file for anything production.
Privacy
Nothing is uploaded. The conversion runs in this tab using your own browser's JavaScript engine — no server sees your data, and the page keeps working with the network disconnected.
FAQ
Why double underscore for nesting?
Because a single underscore is ambiguous — DB_HOST_NAME could be db.host.name or db.hostName. ASP.NET Core and Spring Boot both settled on __ to make the split unambiguous, and other frameworks have followed.
Can I get the JSON back?
Yes — .env → JSON reverses it, including splitting on the separator. Types are inferred on the way back, since env values are always strings.
Does it handle deeply nested config?
Yes, at the cost of long names. Beyond three or four levels, environment variables stop being a good transport — mount the JSON as a file instead.