Skip to main content

.env to JSON Converter

Convert .env files to JSON and back again — quotes, escapes, comments and multi-line values included. Runs in your browser — nothing is sent to a server.

Your secrets stay on your machine. .env files normally hold live API keys, database passwords and tokens. This converter runs entirely in your browser with JavaScript — nothing is uploaded, logged or sent anywhere.

Options

Conversion runs automatically as you type.
0 variables
0 duplicate keys
0 lines skipped

How to Use the .env / JSON Converter

  1. Pick a direction: .env → JSON to parse a dotenv file, or JSON → .env to generate one.
  2. Paste your content into the left panel, or click Load Example to see a worked sample.
  3. The converted result appears on the right automatically after a short pause in typing.
  4. Tick Sort keys alphabetically to normalise ordering, handy for diffing two environments.
  5. Switch JSON output between pretty printed and minified when JSON is the result.
  6. Use Copy for the clipboard, or Download to save env.json / .env.
  7. Check the counters underneath: parsed variables, duplicate keys, and malformed lines that were skipped.

What is a .env File?

A .env file is a plain text file holding environment variables as one KEY=value pair per line. It exists to keep configuration out of source code: database URLs, API keys, feature flags and ports live in the file, and the application reads them at start-up. The pattern comes from the Twelve-Factor App methodology, which argues that config differs between deploys while code does not, so the two should never be mixed.

Nearly every ecosystem has a loader for it — dotenv in Node.js, python-dotenv, godotenv, Laravel and Rails variants, plus native support in Docker Compose, Vite, Next.js and Astro. JSON, meanwhile, is what CI systems, secret managers and container platforms usually want. Converting between the two is a routine chore, which is exactly what this tool automates.

Why .env Has No Formal Specification

There is no RFC, no ISO standard and no reference grammar for the dotenv format. It began as an ad-hoc convention and each library invented its own rules, so parsers genuinely disagree about the same file. The differences are not academic — they silently change the value your application receives.

  • Quoting: some parsers treat quotes as literal characters, others strip them. Most modern ones strip, and treat single quotes as raw while double quotes process escapes.
  • Escape sequences: whether \n becomes a real newline depends on the library, and often on whether the value is double quoted.
  • Inline comments: a # after a value is a comment to some parsers and part of the value to others. A password ending in #hunter2 has broken plenty of deployments.
  • Variable interpolation: a handful of loaders expand $OTHER_VAR inside values; most do not.
  • The export prefix: tolerated by many parsers so the file can also be sourced by a shell, rejected by some.
  • Multi-line values: PEM certificates and private keys need them, but support arrived late and inconsistently.
  • Duplicate keys: almost always last-wins, though a few loaders keep the first occurrence.

This converter follows the behaviour of mainstream Node.js and Python loaders: export is stripped, single quotes are literal, double quotes expand \n \t \r \\ and \", inline comments are stripped only from unquoted values, and the last duplicate wins. Variable interpolation is deliberately not performed — the value you see is the value you get.

A Word About Your Secrets

A .env file is rarely harmless test data. It usually contains live production credentials: database passwords, Stripe and AWS keys, OAuth client secrets, JWT signing keys, SMTP logins. Pasting one into a random web form is the same as emailing it to a stranger, and it is one of the most common ways credentials leak.

This tool never transmits your input. All parsing and generation happens locally in your browser using plain JavaScript — there is no upload, no API request, no analytics event carrying your data, and no server-side processing of any kind. You can disconnect from the network and the converter still works. If you want to confirm that, open your browser developer tools, switch to the Network tab, and watch that nothing is sent while you convert.

Two habits worth keeping regardless of which tool you use: add .env to your .gitignore before the first commit, and commit a .env.example with the keys but empty values so teammates know what to fill in. If a real secret ever reaches a remote branch, rotate it — scrubbing history is not enough once it has been pushed.

How Values Are Converted

Going from .env to JSON, every value becomes a JSON string. That is intentional: environment variables are strings at the operating-system level, so PORT=3000 becomes {"PORT": "3000"} rather than a number. Nothing is guessed or coerced.

Going the other way, the root of your JSON must be an object — an array or a bare string has no keys to turn into variable names, so it is rejected with an inline error. Strings, numbers and booleans are written straight out. null becomes an empty value. Because .env is strictly flat, nested objects and arrays are serialised with JSON.stringify and stored as a quoted JSON string, which your application can parse back after loading.

Any value containing whitespace, a #, a quote character or a backslash is wrapped in double quotes and escaped, so it survives a trip back through the parser unchanged. Values that need no quoting are left bare for readability.

Specifications

Accepts
Text — type or paste
Gives you
.json download · copy to clipboard
Where it runs
Your browser — the file is never uploaded
Sign-up
None
Cost
Free, with no usage limits

FAQ

Is my .env data uploaded anywhere?

No. The converter is written in JavaScript that runs inside your own browser tab. Your input never leaves the page — there is no upload, no fetch to an API, and no server-side processing. You can verify this by opening the Network tab in your browser developer tools and watching that no requests are made while you convert, or simply by going offline and using the tool anyway.

Why are numbers in my JSON output quoted as strings?

Because environment variables are always strings. The operating system, Docker, and every process manager pass them as text, so PORT=3000 genuinely is the string "3000" once loaded. Converting it to a JSON number would be inventing type information that does not exist in the source file, and it would break round-tripping. Cast values in your application code where you know what type they should be.

How are quotes and escape sequences handled?

Single-quoted values are taken literally, so a backslash-n stays as two characters. Double-quoted values expand the escapes \n, \t, \r, \\ and \" into their real characters. Unquoted values are trimmed of surrounding whitespace. This matches the behaviour of the dotenv package in Node.js and python-dotenv, which is what most projects rely on.

What happens to comments in my .env file?

Full lines beginning with # are ignored entirely. A # that follows a space or tab after an unquoted value is treated as a trailing inline comment and removed. Inside single or double quotes, a # is ordinary data and is preserved — which matters if a password or token happens to contain one. Comments are not carried into the JSON output, because JSON has no comment syntax.

Can .env files store nested objects or arrays?

Not natively — the format is a flat list of key-value pairs with no nesting. When converting JSON to .env, this tool serialises any nested object or array with JSON.stringify and stores the result as a quoted string value. Your application can then JSON.parse that variable after loading. If nesting is central to your configuration, a format like YAML or TOML is a better fit than dotenv.

What if my file has duplicate keys or broken lines?

Duplicate keys follow the usual last-one-wins rule, and the tool shows a warning naming the affected keys so the shadowing is not silent. Lines with no equals sign cannot be a variable assignment, so they are skipped and counted in the lines skipped stat. Check that counter after converting — a non-zero value usually means a stray line or a typo rather than something you meant to include.

Related Tools