.env File Parser: Validate & Format
.env file parser: validate syntax, detect duplicates, sort alphabetically, convert to JSON, YAML, or Docker formats. Browser-only.
What Is the .env File Parser?
The .env File Parser & Formatter is a browser-based tool for working with environment variable files. It parses KEY=VALUE content to detect syntax errors, identify duplicate keys, and display file statistics; it converts your variables to JSON, YAML, Docker --env-file, or docker-compose.yml format with a single click; and it merges two .env files together with interactive conflict resolution when the same key appears in both files with different values.
Use it when you need to audit an environment file before deploying, share configuration with a teammate in a different format, combine a base .env with an environment-specific override, or simply sort a long file alphabetically so it is easier to scan. Everything runs in the browser — your secrets never touch a server.
Key Features
- Parse KEY=VALUE pairs with support for quoted values and multiline — single-quoted and double-quoted values are unquoted automatically; inline comments after unquoted values are stripped.
- Detect duplicate keys with warning badges — every key appearing more than once is flagged in the Validation panel with a yellow warning icon.
- Validate syntax: missing =, empty keys, invalid characters — the parser enforces that keys must start with a letter or underscore and contain only alphanumeric characters and underscores (
/^[a-zA-Z_][a-zA-Z0-9_]*$/). Each violation reports the specific line number. - Sort variables alphabetically — the Sort button rewrites the input textarea with variables in ascending lexicographic order, replacing the original content.
- Convert to JSON format — produces a pretty-printed JSON object with all variable keys and values.
- Convert to YAML format — intelligently wraps values in double quotes when the value contains YAML-special characters (
:,#,{,},[,],,,&,*,!,|,>,',",%,@, ``), boolean-like strings (true,false,yes,no,null`), purely numeric strings, or empty values. - Convert to Docker --env-file format — outputs bare
KEY=VALUEpairs with no quoting, as required bydocker run --env-file. - Convert to docker-compose.yml environment block — wraps the output in an
environment:YAML block with list items (- KEY=VALUE), ready to paste into adocker-compose.ymlservice definition. - Merge two .env files with conflict detection and resolution — side-by-side textarea inputs; conflicts are listed with both values so you can choose which one wins before applying.
- Show statistics: variable count, comments, empty lines — four counters display after parsing: Variables, Comments, Empty Lines, and Duplicates.
- File upload support — upload
.env,.env.*, or.txtfiles directly from disk. - 100% client-side processing — your secrets never leave your browser.
How to Use the .env File Parser
Step 1: Enter or Upload Your .env Content
Switch between the two modes using the Parse & Validate and Merge tabs at the top of the tool.
In Parse mode, paste your .env content directly into the input textarea on the left, or click Upload to load a file from disk (accepts .env, .env.*, and .txt files). If you want to explore the tool's behavior without your own data, click Load Example to populate the input with a demo file that includes comments, quoted values, a duplicate key, and an intentionally malformed line.
Example input:
# Application Configuration
APP_NAME=my-awesome-app
APP_ENV=production
APP_PORT=3000
# Database
DATABASE_URL="postgres://user:pass@localhost:5432/mydb"
DATABASE_POOL_SIZE=10
# Duplicate key (triggers warning)
APP_PORT=8080
# Invalid line (triggers error)
MISSING_EQUALS
Step 2: Review the Statistics and Validation Panel
After you type or paste content, two panels appear below the editor:
Statistics shows four counters in a grid:
- Variables — count of valid KEY=VALUE entries
- Comments — lines beginning with
# - Empty Lines — blank lines
- Duplicates — keys appearing more than once (counter turns yellow when non-zero)
Validation lists every issue found:
- Duplicate keys appear with a yellow triangle icon: "Duplicate key: APP_PORT"
- Syntax errors appear with a red X icon, citing the exact line: "Line 14: Missing '=' sign"
- If there are no issues, a green check confirms: "No issues found"
Step 3: Choose an Output Format
The right panel's format selector offers five options:
| Button Label | Output Format | Primary Use Case |
|---|---|---|
.env | KEY=VALUE (requoted) | Clean, normalized .env |
JSON | Pretty-printed JSON object | Config passed to JSON-consuming apps |
YAML | KEY: value (auto-quoted) | Ansible vars, Helm values, app config files |
Docker --env-file | Bare KEY=VALUE, no quoting | docker run --env-file <file> |
docker-compose.yml | environment: list block | Paste into a service definition |
Click any button to switch the output instantly. All formats exclude comment lines and empty lines — only valid variable entries are included.
The .env output format also normalizes quoting: values containing spaces, #, or " are automatically wrapped in double quotes with internal double quotes escaped.
Step 4: Sort and Copy
Click Sort to rewrite the input textarea with variables in alphabetical order. This modifies the input in place, so the sorted content becomes the new source for parsing and output.
Click Copy in the output panel header to copy the formatted result to clipboard.
Step 5: Merge Two .env Files (Optional)
Switch to the Merge tab. Paste or upload one .env file into the File A textarea and another into File B, then click Merge Files.
- If the two files have no conflicting keys (the same key with different values), the merge completes immediately and the result appears in the Parse tab's input for further editing.
- If conflicts exist, a Conflict Resolution panel lists each conflicting key with both values shown as buttons. Click the button for the value you want to keep (A or B), then click Apply Merge to combine the files using your selections.
Practical Examples
Auditing a Production .env Before Deployment
Paste the production environment file and look at the Validation panel. Even a single "Missing '=' sign" error or duplicate key warning can indicate a copy-paste error that would cause a runtime configuration failure. The Statistics counters give you a quick count to cross-reference against your expected variable list.
Converting for Docker
You have a .env file that works with dotenv in Node.js but need to pass it to a Docker container. Select Docker --env-file for use with docker run --env-file .env, or select docker-compose.yml to get a ready-made environment: block:
environment:
- APP_NAME=my-awesome-app
- APP_ENV=production
- DATABASE_POOL_SIZE=10
Paste the block directly into your service definition.
Merging Base and Override Files
Your project has .env.base with shared defaults and .env.local with developer-specific overrides. Load .env.base into File A and .env.local into File B, click Merge Files, resolve any conflicts by choosing the local override value, then copy the merged output as your working .env.
Tips and Best Practices
Upload files instead of pasting for long configs. The file upload button accepts .env, .env.*, and .txt formats. This avoids clipboard size limits and accidental trailing-space corruption that can happen when copying from terminals.
Sort before diffing. If you are comparing two environment files manually, sort both first. The Sort button normalizes ordering so your diff tool can find meaningful changes rather than noise from different variable orderings.
YAML output quotes boolean-like values automatically. The formatter detects strings like true, false, yes, no, and null and wraps them in double quotes. This prevents YAML parsers from interpreting FEATURE_FLAG=true as a boolean true rather than the string "true".
The .env output format re-quotes values with spaces. If your input has SECRET_KEY=my secret with spaces, the .env output will render it as SECRET_KEY="my secret with spaces". This is safe to copy back into any dotenv-compatible loader.
Inline comments on unquoted values are stripped. A line like APP_PORT=3000 # HTTP port will parse the value as 3000, discarding the inline comment. Quoted values such as DESCRIPTION="hello # world" preserve the # as part of the value.
Common Issues and Troubleshooting
"Line N: Missing '=' sign" — The line has content but no equals sign. This is the most common error when pasting shell export statements like export APP_NAME=foo. Remove the export keyword before pasting.
"Line N: Empty key" — A line starts with =, such as =value. The parser requires a non-empty key before the equals sign.
"Line N: Invalid key 'MY-KEY'" — Hyphens are not allowed in environment variable keys by the POSIX standard, and this parser enforces ^[a-zA-Z_][a-zA-Z0-9_]*$. Replace hyphens with underscores: MY_KEY.
Duplicate key warning but values are the same — The parser flags all keys appearing more than once, regardless of whether the values differ. Remove the redundant line from the input.
Merge button is greyed out — Both File A and File B must contain content. The button is disabled if either textarea is empty.
YAML output has unexpected quotes — Values that are purely numeric or match boolean literals (true, false, yes, no, null) are quoted to preserve their string type. This is intentional and correct YAML behavior.
Privacy and Security
The .env File Parser runs entirely in your browser with no server-side processing. Your environment variables — including API keys, database credentials, and secret tokens — are never transmitted over the network. The parsing, validation, format conversion, and merge logic are all JavaScript functions that execute locally. The tool works offline after the initial page load. No third-party analytics scripts have access to the textarea content.
Frequently Asked Questions
Is the .env File Parser free? Yes, completely free with no account required.
Is it safe to paste real API keys and secrets? Yes. All processing happens in your browser using local JavaScript. Nothing is sent to any server. Your secrets stay on your machine.
Can I use it offline? Yes. After the page loads, parsing and conversion work without an internet connection.
Does it support multiline values? The parser handles single-line quoted values. True multiline values spanning multiple lines (using a backslash continuation or heredoc-style syntax) are not currently supported. Split multiline content into a single quoted line before parsing.
Why does my quoted value still appear in the output with quotes stripped? The unquoteValue function removes matching single or double quotes that wrap the entire value. DATABASE_URL="postgres://..." becomes postgres://... internally and is re-quoted as needed in the output format. This is the correct behavior for format conversion.
What happens to comment lines in the output? Comments (lines beginning with #) are excluded from all output formats. Only valid variable entries are included. Comments are counted in the Statistics panel but not written to the output.
Can I merge more than two files? The tool supports merging exactly two files at a time. To merge three or more files, merge A+B first, copy the result into Parse mode, then use that as File A for a second merge with File C.
Does the sort operation preserve comment lines? No. The Sort button uses only the parsed valid variables to reconstruct the sorted input, discarding comment lines and empty lines. Use Sort when you want a clean, normalized file.
What is the Docker --env-file format? docker run --env-file expects bare KEY=VALUE lines with no shell quoting. The Docker output format omits quotes even for values with spaces, which is correct for the Docker format but would fail in a shell script. Use the .env format if you need shell-safe quoting.
Can I detect which variables differ between two files without merging? Switch to Merge mode and click Merge Files. The conflict list shows every key where File A and File B have different values, which serves as a practical diff of differing variables.
Related Tools
- Config Generator — Generate structured configuration files for various frameworks and environments.
- Docker Converter — Convert between Docker-related configuration formats.
- YAML to TOML — Convert between YAML and TOML configuration file formats.
Try .env File Parser now: .env File Parser & Formatter