How .env values map to JSON types
Every value in a .env file is text. Your runtime never sees a number or a boolean: process.env.PORT in Node.js and os.environ["PORT"] in Python are both strings. The converter can show either view, depending on the coerce types switch.
| .env line | coerce on | coerce off | Rule |
|---|---|---|---|
PORT=3000 | 3000 | "3000" | whole numbers within the safe integer range |
RATE=0.25 | 0.25 | "0.25" | decimals with digits on both sides of the dot |
DEBUG=true | true | "true" | only the exact lowercase words true / false |
DSN=null | null | "null" | only the exact word null |
EMPTY= | "" | "" | empty stays an empty string |
ID=9007199254740993 | "9007199254740993" | same | too big for a JS number, kept as text |
ZIP=01067 | "01067" | same | leading zeros are kept as text |
True, YES or 1 are not turned into booleans, on purpose: libraries disagree about them, and guessing would hide bugs. Validate those in your app, or check the file first with the .env validator.
Parsing rules the converter follows
- Comments: lines starting with
#are skipped. An unquoted value ends at#(space + hash). Inside quotes,#is part of the value. - Quotes: double and single quotes are removed. In double quotes,
\"becomes". - export:
export KEY=value(shell style) is read asKEY=value. - Key names: must match
[A-Za-z_][A-Za-z0-9_]*. Lines with invalid names are skipped. Run the .env validator to see which ones. - Multi-line values: a quoted value spanning several lines (for example a PEM private key) is not supported. Store it on one line with
\nescapes.
Doing the same in code
When you need the conversion inside a script or a CI job, every ecosystem has a parser that returns a plain object of strings:
# Node.js (dotenv)
node -e 'const fs=require("fs");console.log(JSON.stringify(require("dotenv").parse(fs.readFileSync(".env")),null,2))'
# Python (python-dotenv)
python -c 'import json;from dotenv import dotenv_values;print(json.dumps(dotenv_values(".env"),indent=2))'Both return strings only, which equals the converter with coercion off. To go back from JSON to a .env file, use the JSON to ENV converter; to compare two .env files key by key, use the ENV diff checker.