Dotenv converter

What is a Dotenv Converter?

Dotenv files store configuration as simple KEY=value lines and are used by Node.js, Python, Docker Compose and most deployment platforms. JSON is often needed when moving that configuration into a cloud console, a secrets manager, a test fixture or code. This converter translates between the two formats.

How to use it

  1. Paste the contents of a .env file to get JSON.
  2. Or paste a flat JSON object to get dotenv lines.
  3. Copy the result.

Example

Input:

# Database
DB_HOST=localhost
DB_PORT=5432
APP_NAME='My App'
export DEBUG=true

Output (with double quotes in real JSON):

{ 'DB_HOST': 'localhost', 'DB_PORT': '5432', 'APP_NAME': 'My App', 'DEBUG': 'true' }

Dotenv syntax rules

  • Lines starting with # are comments.
  • An optional export prefix is allowed for shell compatibility.
  • Quoted values can contain spaces and #. Double quotes usually allow escape sequences like \n; single quotes are literal.
  • All values are strings. 5432 and true must be converted by your application.
  • Keys are conventionally uppercase with underscores.

Security reminders

  • Never commit real .env files. Add .env to .gitignore and commit an .env.example with placeholder values.
  • Conversion runs entirely in your browser, but avoid pasting production secrets into any online tool on shared machines.

Frequently Asked Questions

Why are all values strings in the JSON output?

Environment variables are always strings. Your application must convert numbers and booleans itself.

Are comments preserved?

Comments are skipped when converting to JSON, because JSON has no comment syntax.

Can it handle nested JSON?

Dotenv is flat, so use a flat JSON object of keys and values. Nested objects need to be flattened first.

Should I commit my .env file?

No. Commit an .env.example with placeholder values and keep the real .env file out of version control.

How do I load a .env file in Node.js?

Node.js 20.6 and later can load it with the --env-file flag. On older versions, use the dotenv package and call its config function at startup.