How do I convert a .env file to JSON?
Paste your .env file and this tool reads it line by line into a JSON object, skipping blank lines and comments, stripping any leading export, and removing surrounding quotes from values. Switch modes to turn a JSON object back into KEY=value lines. It all runs in your browser, so nothing is uploaded.
What a .env file is
A .env file is a plain text list of configuration settings, one per line, in the form KEY=value. Frameworks and libraries load it at start-up so that things like database hosts, port numbers and secret API keys live outside your code. Keeping them in a .env file means the same code can run on your laptop, a colleague's machine and a live server with different settings each time, and it keeps secrets out of your source files.
Sometimes you want that same information as JSON instead, to feed a script, seed a config object, or compare two environments side by side. This converter reads a .env file line by line and gives you a clean JSON object, and it also runs in reverse to turn a JSON object back into KEY=value lines. Everything happens in your browser, so your keys and passwords are never uploaded.
How the parsing works
Each line is split on its first equals sign, so a value can safely contain more equals signs. Blank lines are ignored, and a line whose first non-space character is a hash is treated as a comment and skipped. An optional leading export is removed, so a line copied straight from a shell script still works. Keys and values are trimmed of surrounding spaces, and if the same key appears twice the last one wins, which is how most loaders behave.
Notice that every value is a string, including the port number. A .env file has no idea about types: everything is text, so 5432 stays as the text "5432" and true stays as the text "true". If your program needs a real number or boolean, it should convert it after loading.
Quoting gotchas
Quotes are the part people trip over. A value wrapped in matching single or double quotes has those outer quotes removed, so GREETING="hello world" gives you hello world, not "hello world". Inside double quotes, the two characters backslash and n are turned into a real line break, which lets a single line hold multi-line text. Single quotes are literal: nothing inside them is unescaped. Going the other way, this tool wraps a value in double quotes only when it needs to, meaning when the value contains a space, a hash or a newline.
One thing this tool deliberately does not do is strip an inline comment after a value, because a hash can be a genuine part of a value such as a colour code or a URL fragment. Keep comments on their own lines to avoid surprises.
Never commit your secrets
A .env file usually holds real secrets: database passwords, payment keys, tokens that can spend money or leak customer data. Add it to your .gitignore so it never lands in version control, and share only a redacted .env.example with placeholder values so teammates know which keys they need. If a secret ever does get committed, treat it as compromised and rotate it, because git history keeps a copy even after you delete the file. This converter helps here too: because it runs entirely in your browser and sends nothing to any server, you can paste a real .env in without it leaving your device.
How we work it out
Each .env line is split on its first equals sign into a key and value, with blank and commented lines ignored, an optional leading export removed, and matching single or double quotes stripped (double-quoted values also have \n unescaped). Duplicate keys keep the last value. The reverse mode emits KEY=value lines, quoting values that contain spaces, a hash or a newline.
Frequently asked questions
Is my .env file or JSON sent anywhere?
No. The conversion runs entirely in your browser with plain JavaScript. Your text is never uploaded, logged or seen by anyone, which matters because .env files often hold secrets like API keys and database passwords.
How are comments and blank lines handled?
Blank lines are ignored, and any line whose first non-space character is a hash is treated as a comment and skipped. Inline comments after a value are not stripped, because a hash can be a valid part of a value, so keep comments on their own lines.
What happens to quotes around values?
A value wrapped in matching single or double quotes has those outer quotes removed. Inside double quotes, the sequence backslash-n is turned into a real line break. Single-quoted values are kept literally, with no unescaping.
What if the same key appears twice?
The last occurrence wins, which mirrors how most tools load a .env file. Earlier duplicate keys are overwritten in the resulting JSON object, so only the final value for each key is kept.
Should I commit my .env file to git?
No. A .env file usually contains secrets, so add it to your .gitignore and share only a redacted .env.example with placeholder values. This tool never uploads anything, but a committed .env is public to anyone with repository access.