.env to JSON Converter
Preserve dotenv strings, reject duplicate names and review optional JSON key flattening
Dotenv subset: letter/digit/underscore names, never starting with a digit; export, comments and quoted multiline values. Single quotes are literal; double quotes expand only \n / \r (dotenv 17 rules; Node’s built-in reader leaves \r literal). The first matching quote ends a value; escaped quotes are unsupported. Unquoted # starts a comment. No expansion or execution. Reverse conversion preserves top-level names by default and writes objects/arrays as JSON text; unrepresentable quote combinations are errors.
Input ≤2 MiB; output and name mappings each ≤8 MiB; depth ≤128; values ≤100000; keys or generated paths ≤8192 characters; numeric tokens ≤256 characters. Duplicate keys, collisions, negative zero, non-finite numbers, NUL and unpaired Unicode surrogates are rejected. JSON numbers must round-trip to the same decimal value; integers are limited to ±9007199254740991.
Configuration is processed locally in this page without uploading content or saving input drafts. Analytics exclude keys, values and results. After copying or downloading, check the target application’s configuration rules.
About this tool
This converter implements a declared dotenv subset with portable variable names, optional export, comments and quoted multiline values. Values stay strings by default; optional inference applies only to unquoted strict JSON primitives, arrays and objects. Single quotes are literal, while double quotes expand only backslash-n and backslash-r using dotenv 17 behavior; Node’s built-in reader leaves backslash-r literal. The first matching quote ends a value, so escaped quotes are unsupported. Physical CR/CRLF line breaks in quoted input normalize to LF. Duplicate names are errors. Reverse conversion preserves top-level names by default, encodes nested values as compact JSON text, and optionally flattens names with collision checks and a visible mapping. Quote combinations that cannot be emitted faithfully are rejected. References are not expanded and commands are not executed; this is not a shell script generator. Conversion runs locally in the page without uploading configuration, retaining input drafts, or placing keys and values in analytics. Copy and download contain the complete current result; the screen preview is bounded. Input is limited to 2 MiB, depth to 128, values to 100000, keys or generated paths to 8192 characters, and output and name mappings to 8 MiB each. Numeric tokens are limited to 256 characters. NUL and unpaired Unicode surrogates are rejected.
Scenario Recipes
Generate environment names and verify a Windows path
Goal: Flatten a nested connection object without losing a backslash path or creating a duplicate name.
- Choose JSON → .env and paste {"db":{"host":"localhost","port":5432},"path":"C:\\new\\test","empty":{}}.
- Enable flattening, convert and review DB_HOST, DB_PORT, PATH and EMPTY in the mapping. PATH must use literal single quotes.
- Add a top-level db_host field and convert again to see the collision error. Remove or rename the conflicting field intentionally, then export and read it with the target dotenv library.
Result: A checked name mapping with DB_PORT represented as environment text, an intact Windows path and an explicit empty-object value.
Failure Clinic (Common Pitfalls)
Two nested paths generate the same environment name
Cause: Uppercasing, punctuation replacement and underscore joining are not reversible. a-b, a.b, a_b and nested a.b can all produce A_B.
Fix: Leave flattening off when valid top-level names already exist. When flattening is required, inspect the mapping and resolve every collision in the source instead of accepting an overwritten variable.
A quoted value reads differently in another runtime
Cause: Dotenv has dialect differences: dotenv 17 decodes double-quoted backslash-r, while Node’s built-in reader leaves it literal. Escaped matching quotes and shell expansion also vary across readers.
Fix: Use the declared quote subset, preserve Windows paths with literal single quotes, and test generated text in the application’s actual reader. A representation error means the writer cannot preserve that combination; do not remove backslashes just to make conversion succeed.
Production Snippets
Flattened output preserves backslash text
text
JSON:
{"db":{"host":"localhost","port":5432},"path":"C:\\new\\test","empty":{}}
With flattening enabled:
DB_HOST=localhost
DB_PORT=5432
PATH='C:\new\test'
EMPTY={}
Ordinary dotenv readback:
{"DB_HOST":"localhost","DB_PORT":"5432","PATH":"C:\\new\\test","EMPTY":"{}"}Frequently Asked Questions
Which assignment names and comments are accepted?
Names match [A-Za-z_][A-Za-z0-9_]*. An optional export prefix is accepted. Unquoted # starts a comment even without a preceding space; # inside quotes is text. Malformed assignments, trailing text after a closing quote and duplicate names are rejected. __proto__ is retained as own data, although some downstream readers omit it.
Which quotes, escapes and multiline values are supported?
Single quotes are literal. Double quotes expand only backslash-n and backslash-r, following dotenv 17; Node’s built-in parser expands backslash-n but leaves backslash-r literal. Physical CR/CRLF breaks normalize to LF. The first matching quote closes the value; escaped matching quotes, generic backslash unescaping and framework-specific quoting extensions are unsupported.
Why do numbers and booleans remain strings?
Environment variables are text, so string preservation is the default. Enable inference only when needed: unquoted true/false/null, strict JSON numbers, arrays and objects become JSON values. Quoted values and 00123 remain strings. Unsafe integers, changed decimals, negative zero and duplicate JSON keys are rejected during inference.
How does JSON become dotenv, and can flattened names collide?
The JSON root must be an object. By default, valid top-level names retain case; arrays and objects become compact JSON text. Optional flattening uppercases and sanitizes path segments, joining them with underscores. Generated collisions such as a_b and nested a.b are errors. Empty objects remain {} values; the mapping shows every generated name.
Is reverse conversion a universal dotenv or shell serializer?
No. The writer chooses literal single quotes or supported double quotes without silently changing text, and rejects combinations it cannot preserve. Values containing carriage returns use backslash-r, which dotenv 17 reads but Node’s built-in parser does not decode. All environment values remain strings after a typical dotenv read. Variable references and command-looking text are literal here; do not assume a shell or expansion plugin will behave the same way.
Are secrets saved or uploaded, and are exports complete?
Conversion runs locally in the page without uploading configuration, retaining input drafts, or placing keys and values in analytics. Copy and download contain the complete current result; the screen preview is bounded. Input is limited to 2 MiB, depth to 128, values to 100000, keys or generated paths to 8192 characters, and output and name mappings to 8 MiB each. Numeric tokens are limited to 256 characters. NUL and unpaired Unicode surrogates are rejected.
Keep browsing