.env to JSON Converter
Convert a .env (dotenv) file into JSON. It strips export prefixes and comments, unquotes single- and double-quoted values (handling escapes), and optionally coerces true/false, numbers and null to real JSON types, lower-cases keys, and nests keys into a structured object by splitting on double-underscore (DB__HOST) or dot (db.host). Everything runs in your browser, so secrets in the file never leave your machine.
How to use the .env to JSON Converter
Paste the contents of a .env file. The parser reads one KEY=value per line, ignoring blank lines and # comments, dropping a leading export, and removing surrounding quotes — inside double quotes it also interprets \n, \t and escaped quotes the way dotenv loaders do. Quoted values are always kept as strings; unquoted values are where the options apply.
Turn on coerce types to convert unquoted true/false to booleans, null to null, and bare integers and decimals to numbers — so PORT=3000 becomes the number 3000 rather than the string "3000". Leave it off to keep every value a string, which is closer to how the shell and process.env actually see them. Use Nesting to build a structured object: split on __ turns DB__HOST and DB__PORT into { "DB": { "HOST": …, "PORT": … } } (the convention many config libraries use), and split on . does the same for dotted keys. Lower-case keys normalizes the conventionally upper-case env names if your config expects lower-case. The conversion is one-way and local; nothing is uploaded, but remember the JSON output still contains any secrets that were in the file.
From dotenv to structured JSON
The .env file is the near-universal way to keep configuration and secrets out of source code. Each line is a simple KEY=value pair, loaded into the process environment by a dotenv library or the shell. It is deliberately minimal: everything is a string, there is no nesting, and the only structure is convention. That simplicity is why it is everywhere — and also why it sometimes needs converting into a richer format.
JSON is the natural target when configuration has to be structured or typed. A growing app often outgrows a flat string map: it wants a real boolean for a feature flag, a number for a port or a pool size, and grouped settings like a database block rather than a dozen DB_-prefixed keys. Several configuration systems already bridge this gap with a naming convention — environment variables with a double-underscore separator are mapped to nested keys (ASP.NET Core and many Node config libraries do exactly this), so DB__HOST is understood as DB:HOST. Converting a .env to JSON with that same convention produces the structured document those systems, or your own code, can consume directly.
The conversion has a few subtleties worth doing correctly. Values may be quoted to preserve whitespace or special characters, and a double-quoted value can contain escape sequences that should be unescaped; a # after an unquoted value begins a comment and must be trimmed. Type coercion is a judgement call — true and 3000 are strings in the environment, and turning them into a boolean and a number is convenient but changes meaning, so it is offered as a toggle rather than forced. This tool handles the quoting, comments and export prefix the way common loaders do, then applies your choices for coercion, key case and nesting, all in the browser. Because a .env typically holds credentials, doing the conversion locally — with nothing uploaded — is the safe way to reshape it.
Common use cases
- Config migration. Convert a flat .env into a nested JSON config file using the __ convention.
- Typed settings. Coerce ports, flags and counts to real numbers and booleans for a JSON consumer.
- Tooling input. Feed environment values into a script or template that expects JSON rather than KEY=value.
- Inspection. Read a long .env as structured, grouped JSON to spot duplicates and stragglers.