.env to JSON Converter
Paste a .env file, get JSON instantly. Your database passwords, API keys and tokens never leave your browser — 100% private, no upload, free dotenv parser.
Options · 2 spaces · strings
What is a .env File?
A .env file (dotenv file) is a plain-text list of KEY=VALUE pairs used to keep configuration and secrets out of source code. It is the de facto standard for environment variables in Node.js, Vite, Next.js, Python, Ruby, Docker Compose and almost every modern framework — the dotenv library and its ports load the file and inject each pair into the process environment. Because the file commonly contains database passwords, API keys, OAuth client secrets and access tokens, it is almost always git-ignored and treated as sensitive.
Converting a .env file to JSON is a frequent task: you need to feed configuration into a tool that reads JSON, validate it against a JSON Schema, import it into a secrets manager, generate typed config objects, or simply inspect a long .env at a glance as structured data. This converter turns the flat list of pairs into a single JSON object, one property per key.
This tool is built around a few deliberate decisions:
**1. Strings by default, types on demand.** dotenv never coerces types — at runtime every process.env value is a string. The default output honours that exactly, so the JSON matches what your app actually sees. When you want typed JSON, the optional Infer types switch promotes unquoted numbers, booleans and null values, while quoted values stay strings because the quotes are an explicit signal.
**2. Faithful dotenv parsing.** Comments, blank lines, the export prefix, single vs. double quotes, escape sequences, multi-line double-quoted values and inline comments on unquoted values are all handled the way the dotenv library handles them — no surprises when you compare the JSON against what your application loads.
**3. Duplicate-key safety.** When a key is defined twice the later value wins, and a warning tells you which keys were duplicated so an accidentally shadowed secret never slips by unnoticed.
**4. 100% browser-based privacy.** Your .env data never leaves the browser. There is no upload, no server round-trip and no logging — you can verify zero network requests in the DevTools Network tab. This is the only responsible way to convert a real .env online, since the file is essentially a list of credentials.
After converting, you can pretty-print or validate the result with the JSON Formatter, escape it for embedding in another string with JSON Escape, or go the other way with the companion JSON to .env Converter. If your configuration lives in YAML instead, try YAML to JSON.
// Parse a .env file to a JSON object in Node.js using dotenv
import { parse } from 'dotenv';
const envText = `# Database
DATABASE_URL=postgres://user:pass@localhost:5432/mydb
DEBUG=true`;
// dotenv.parse returns a plain object of string values
const parsed = parse(envText);
// Every value is a string, just like process.env
const json = JSON.stringify(parsed, null, 2);
console.log(json);
// {
// "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb",
// "DEBUG": "true"
// } Key Features
Faithful dotenv Parsing
Handles comments, the export prefix, single and double quotes, escape sequences (\n \t \r \\ \"), multi-line double-quoted values and inline comments — exactly the way the dotenv library does.
Strings by Default, Types on Demand
Values are JSON strings by default to match dotenv's runtime behavior. Flip on Infer types to promote unquoted numbers, booleans and null values; quoted values always stay strings.
Duplicate-Key Warnings
If a key is defined twice the last value wins (dotenv behavior) and a warning lists every duplicated key, so a silently overwritten secret cannot slip past unnoticed.
Live Conversion
JSON output updates instantly as you type or paste. Large inputs (over 200KB) automatically switch to manual mode with a Convert button to keep the browser responsive.
Indent 2 or 4 Spaces
Switch between 2-space and 4-space indentation for the JSON output to match your codebase style or downstream tooling.
100% Browser-Based Privacy
All parsing runs locally in your browser. Your .env data — database passwords, API keys, tokens — is never uploaded, never logged and never stored on any server.
Examples
Node / Vite .env
# Database DATABASE_URL=postgres://user:pass@localhost:5432/mydb DATABASE_POOL_SIZE=10 # Auth JWT_SECRET="super secret value" SESSION_TIMEOUT=3600 # Feature flags ENABLE_SIGNUP=true VITE_API_BASE=https://api.example.com
{
"DATABASE_URL": "postgres://user:pass@localhost:5432/mydb",
"DATABASE_POOL_SIZE": "10",
"JWT_SECRET": "super secret value",
"SESSION_TIMEOUT": "3600",
"ENABLE_SIGNUP": "true",
"VITE_API_BASE": "https://api.example.com"
} A typical Node.js / Vite .env file. By default every value becomes a JSON string (the dotenv standard). Comment lines and blank lines are skipped. Turn on Infer types if you want 10 → number and true → boolean.
Docker Compose environment
POSTGRES_DB=mydb POSTGRES_USER=admin POSTGRES_PASSWORD=s3cr3t! PGDATA=/var/lib/postgresql/data TZ=UTC NGINX_HOST=example.com NGINX_PORT=80
{
"POSTGRES_DB": "mydb",
"POSTGRES_USER": "admin",
"POSTGRES_PASSWORD": "s3cr3t!",
"PGDATA": "/var/lib/postgresql/data",
"TZ": "UTC",
"NGINX_HOST": "example.com",
"NGINX_PORT": "80"
} Turn the env_file your Docker Compose stack reads into JSON so you can load it into a script, a config validator, or a secrets manager. Nothing is uploaded — safe for real credentials.
CI secrets template with export prefix
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY export AWS_REGION=us-east-1 export DEPLOY_ENV=production
{
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"AWS_REGION": "us-east-1",
"DEPLOY_ENV": "production"
} Shell-style .env files often prefix each line with export so they can be sourced. The parser strips the export prefix automatically and gives you clean JSON keys.
Complex .env: quotes, escapes, multi-line and inline comments
APP_NAME=My App # unquoted value, inline comment stripped GREETING="Hello,\nWorld" # double quotes: \n becomes a real newline LITERAL='no \n escapes here' # single quotes: kept literally PRIVATE_KEY="-----BEGIN KEY----- line two line three -----END KEY-----" EMPTY=
{
"APP_NAME": "My App",
"GREETING": "Hello,\nWorld",
"LITERAL": "no \\n escapes here",
"PRIVATE_KEY": "-----BEGIN KEY-----\nline two\nline three\n-----END KEY-----",
"EMPTY": ""
} Shows every dotenv edge case at once: inline comments on unquoted values are removed, double-quoted values process \n \t \r \\ \" escapes, single-quoted values are kept literally, and a double-quoted value can span multiple lines until the closing quote (useful for PEM keys).
How to Use
- 1
Paste Your .env File
Enter or paste your .env contents into the input field above. You can also click 'Load example' to try a Node/Vite .env, a Docker Compose env file, or a CI secrets template.
- 2
See Live JSON Output
JSON appears instantly in the output panel. Toggle 'Infer types' if you want numbers and booleans instead of strings, and pick 2 or 4 space indentation.
- 3
Copy or Download
Click Copy to grab the JSON to your clipboard, or Download to save it as a .json file — ready for a config loader, a secrets manager, or any tool that reads JSON.
Common .env Pitfalls
Missing = Sign on a Line
Every non-comment, non-empty line must be a KEY=VALUE pair. A line with no = sign cannot be parsed and the tool reports an error with the line number. A bare key with no value should be written as KEY= (empty value).
DATABASE_URL DEBUG true
DATABASE_URL= DEBUG=true
Spaces Around the = Sign
dotenv splits on the first = with no spaces around it. Writing KEY = value makes the key 'KEY ' (with a trailing space) and the value ' value' (with a leading space). Remove the spaces, or quote the value if it must contain leading whitespace.
API_KEY = abc123
API_KEY=abc123
Unquoted Value Eaten by an Inline Comment
On an unquoted value, a space followed by # starts an inline comment and everything after it is dropped. If your value legitimately contains a #, wrap the value in quotes so the # is preserved.
COLOR=#ff0000
COLOR="#ff0000"
Expecting Escapes in Single Quotes
Single-quoted values are literal — \n stays as a backslash and an n, it does not become a newline. Use double quotes when you want escape sequences like \n, \t or \" to be processed.
GREETING='Hello\nWorld'
GREETING="Hello\nWorld"
Unclosed Double Quote in a Multi-line Value
A double-quoted value can span multiple lines, but it must be closed with a matching double quote. If the closing quote is missing, the parser keeps consuming lines to the end of the file. Make sure multi-line secrets like PEM keys end with a closing quote.
KEY="-----BEGIN----- line two
KEY="-----BEGIN----- line two -----END-----"
Duplicate Keys Silently Overwritten
If the same key appears twice, the last value wins and the earlier one is lost. The tool warns you, but the cleanest fix is to remove the duplicate so the intended value is unambiguous.
PORT=3000 PORT=8080
PORT=8080
Common Use Cases
- Feed Config into JSON-Based Tooling
- Convert a .env file to JSON to load environment configuration into tools, scripts and SDKs that read JSON rather than environment variables — config validators, schema checkers and code generators.
- Import Secrets into a Manager
- Many secret managers (AWS Secrets Manager, Vault, Doppler) accept JSON for bulk import. Convert a .env file to a JSON object first, then push the whole set in one operation instead of one variable at a time.
- Inspect a Long .env at a Glance
- Turn a sprawling .env file into structured, indented JSON so you can scan keys, spot duplicates via the warning, and review configuration in a readable format before committing changes.
- Generate Typed Config Objects
- Enable Infer types to get numbers, booleans and null in the JSON, then feed it into a typed config layer or a JSON-to-TypeScript step to derive an interface for your environment variables.
- Validate Against a JSON Schema
- Convert .env to JSON and run it through a JSON Schema validator to enforce required keys, value formats and allowed enums in CI — catching misconfigured environments before deploy.
- Migrate Docker Compose env_file Config
- Turn the env_file your Compose stack reads into JSON for use in another orchestration tool, a config server, or documentation — without exposing real credentials to any external service.
Technical Details
- Line-by-Line dotenv-Compatible Parsing
- Input is parsed line by line. Blank lines and comment lines (first non-whitespace character #) are skipped, an optional export prefix is removed, and each remaining line is split on the first = into key and value. Keys are trimmed of surrounding whitespace. Values follow dotenv rules: double quotes process \n \t \r \\ \" escapes and allow multi-line spans, single quotes are literal, and unquoted values strip trailing whitespace and inline comments.
- Optional Type Inference
- By default all values are emitted as JSON strings, matching dotenv's runtime behavior where process.env values are always strings. With Infer types enabled, unquoted values are promoted: numeric strings become JSON numbers, true/false become booleans, and empty or null values become JSON null. Quoted values are never inferred — the quotes mark them as explicit strings. Duplicate keys resolve last-wins with a warning.
- Browser-Based — No Upload, No Server
- All processing happens entirely in your browser's JavaScript engine; no .env data is transmitted over the network at any point. There are no external dependencies because the parser is written in-house — the Node dotenv library relies on the file system and is not browser-safe. Inputs larger than 200KB switch from live mode to manual mode (an explicit Convert click) to keep the browser responsive.
Best Practices
- Keep the Default String Output to Match dotenv
- dotenv loads every value as a string, so the default string output reflects exactly what your application sees at runtime. Only enable Infer types when the downstream consumer genuinely expects typed JSON — otherwise you risk a mismatch where '0' or 'false' behaves differently in JSON than in your running app.
- Quote Values Containing # or Whitespace
- On unquoted values a space followed by # starts an inline comment, and trailing whitespace is trimmed. If a value legitimately contains a # (hex colors, fragment URLs) or meaningful spaces, wrap it in double quotes so it is preserved verbatim in the JSON.
- Resolve Duplicate Keys at the Source
- The tool keeps the last value and warns you when a key is duplicated, but a duplicate in a .env file is almost always a mistake. Remove the redundant line so there is no ambiguity about which secret is active.
- Never Paste Production Secrets into Server-Side Converters
- Because a .env file is effectively a list of credentials, only convert it in a tool that runs entirely in the browser. This converter does — verify zero network requests in DevTools — so it is safe for real secrets, unlike server-side or API-backed converters.
- Validate the JSON Before Using it Downstream
- After converting, run the JSON through the JSON Formatter to confirm the structure before feeding it into a schema validator, a secrets manager import, or a config loader, so a structural surprise surfaces early.
Frequently Asked Questions
How do I convert a .env file to JSON online?
Are values converted to numbers and booleans, or kept as strings?
What happens if the same key appears twice in my .env file?
How are quotes, escapes and multi-line values handled?
Is this parser consistent with the dotenv library?
Can it handle nested or grouped configuration?
Is my .env data sent to a server?
Related Tools
View all tools →Base64 Decoder & Encoder
Encoding & Formatting
Decode and encode Base64 online for free. Real-time conversion with full UTF-8 and emoji support. 100% private — runs in your browser. No signup needed.
Base64 to Image Converter
Encoding & Formatting
Decode a Base64 string or data URI back into an image in your browser. Preview, read dimensions & MIME, then download as PNG, JPG, GIF, SVG. No upload.
CSV to JSON Converter
Encoding & Formatting
Convert CSV to JSON in your browser. RFC 4180, type inference, header row, big-int safe. 100% private, no upload.
HTML to Markdown Converter
Encoding & Formatting
Convert HTML to clean Markdown in your browser — GFM tables, task lists, and links. Choose ATX/Setext headings and inline or reference links. Great for migrating web content or feeding LLMs. 100% private, no upload.
Image to Base64 Converter
Encoding & Formatting
Convert images to Base64 data URIs in your browser — PNG, JPG, GIF, WebP, SVG, ICO. Copy HTML, CSS, Markdown & JSON, with the exact size increase. 100% private, no upload.
JSON Diff & Compare
Encoding & Formatting
Compare two JSON files instantly in your browser. Side-by-side highlighting, RFC 6902 JSON Patch output, ignore noisy fields like timestamps and IDs. 100% private, no upload.