Skip to content

.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.

No Tracking Runs in Browser Free
Options · 2 spaces · strings
Indent
0 chars
JSON Output
0 lines
Reviewed for dotenv parsing compatibility, quote and escape handling, and duplicate-key behavior — Go Tools Engineering Team · Jun 12, 2026

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. 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. 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. 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).

✗ Wrong
DATABASE_URL
DEBUG true
✓ Correct
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.

✗ Wrong
API_KEY = abc123
✓ Correct
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.

✗ Wrong
COLOR=#ff0000
✓ Correct
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.

✗ Wrong
GREETING='Hello\nWorld'
✓ Correct
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.

✗ Wrong
KEY="-----BEGIN-----
line two
✓ Correct
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.

✗ Wrong
PORT=3000
PORT=8080
✓ Correct
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?
Paste the contents of your .env file into the input field above. The tool parses it to JSON instantly in your browser — no button click needed. Each KEY=VALUE line becomes a JSON property. You can choose 2 or 4 space indentation from the Options panel, then click Copy to grab the JSON or Download to save it as a .json file. Everything runs locally, so your secrets never leave your device.
Are values converted to numbers and booleans, or kept as strings?
By default every value is kept as a string, exactly matching the dotenv standard. dotenv itself never coerces types — process.env values are always strings — so this default keeps the JSON faithful to what your application actually sees at runtime. If you would rather have typed JSON, turn on the Infer types option. With it enabled, unquoted values that look like numbers become JSON numbers, true and false become booleans, and an empty or null value becomes JSON null. Quoted values are always kept as strings even with Infer types on, because the quotes signal an explicit string.
What happens if the same key appears twice in my .env file?
Following dotenv behavior, the last occurrence wins — the later value overwrites the earlier one. Because a silently dropped value is a common source of misconfiguration, the tool also shows a non-blocking warning listing exactly which keys were duplicated, so you can confirm which value ended up in the JSON. The output is still a valid JSON object with one entry per key.
How are quotes, escapes and multi-line values handled?
Double-quoted values process escape sequences: \n becomes a newline, \t a tab, \r a carriage return, \\ a backslash and \" a literal double quote. A double-quoted value may also span multiple lines until the closing quote — handy for PEM private keys and certificates. Single-quoted values are treated literally with no escape processing, just like the shell. Unquoted values run to the end of the line, with trailing whitespace removed and inline comments stripped (a space followed by # starts a comment). This matches how the dotenv library parses files.
Is this parser consistent with the dotenv library?
Yes. The parsing rules follow the widely used dotenv conventions: # comment lines and blank lines are ignored, the optional export prefix is removed, keys are split on the first = sign, single quotes are literal, double quotes process escapes and allow multi-line values, unquoted values strip surrounding and trailing whitespace, and all values default to strings. The optional Infer types switch is an extra convenience layered on top — it is off by default precisely so the output matches what dotenv would load.
Can it handle nested or grouped configuration?
.env files are intentionally flat — a list of key/value pairs with no nesting. This converter produces a single flat JSON object that mirrors that structure one-to-one. If your application reads grouped config (for example DB_HOST and DB_PORT), the keys stay flat in the JSON; you can reshape them in code afterwards. If you need true nested structures, a format like YAML to JSON is a better fit, and you can pretty-print the result with the JSON Formatter.
Is my .env data sent to a server?
No. All parsing happens entirely in your browser with JavaScript. Your .env contents — which typically hold database passwords, API keys, OAuth secrets and access tokens — are never transmitted, never stored on any server, and never logged. You can confirm this by opening your browser's Network tab and watching that pasting the file triggers zero requests. This is what makes it safe to convert a real production .env, not just a sanitized sample.

Related Tools

View all tools →