Converters

.env to JSON Converter

Convert dotenv variables to JSON and back without uploading configuration values.

What the .env and JSON converter supports

In .env to JSON mode, the parser accepts blank lines, comments, optional export prefixes, common environment variable names, unquoted values, and single-, double-, or backtick-quoted values. Double-quoted newline, carriage return, tab, quote, and backslash escapes are decoded. Quoted values can span lines, while inline comments outside quotes are removed.

Loading tool...

Type inference and duplicate handling

  • By default every parsed environment value remains a string, which reflects how operating systems expose process variables.
  • Optional inference converts true, false, null, and unambiguous JSON-style numbers; values such as 0012 remain strings to preserve leading zeros.
  • If a key appears multiple times, the final value is emitted and a warning identifies the duplicate definitions.
  • JSON output uses a prototype-safe dictionary so special names such as __proto__ remain ordinary data keys.

How JSON is written as dotenv text

JSON to .env mode requires a top-level object whose keys are valid environment variable names. Strings are double-quoted and escaped, numbers and booleans are written as literals, null becomes an empty string with a warning, and arrays or nested objects become quoted JSON strings. Review structured values because the receiving application decides whether and how to parse them again.

Privacy and dialect differences

Conversion runs in the browser and this tool does not upload field values. Dotenv syntax is a convention with implementation differences: interpolation, command substitution, export handling, and escape rules may vary between Node.js, Docker, shells, and framework-specific loaders. Validate the generated file with the exact runtime that will consume it, and prefer sanitized examples over production credentials.

Related developer tools

Continue with YAML to JSON, JSON Formatter, Timestamp Converter.

How to Use .env to JSON Converter

  1. Choose .env to JSON or JSON to .env and paste a sanitized configuration sample.
  2. For .env input, decide whether JSON primitives should be inferred or all values should remain strings.
  3. Convert and review duplicate-key or structured-value warnings.
  4. Copy the result and validate it with the exact application or dotenv loader that will consume it.

Frequently Asked Questions

Are values in a .env file always strings?

Environment variables are strings at the process boundary. Optional inference is a convenience for JSON output and converts only clear booleans, JSON-style numbers, and null; leave it disabled when exact string preservation matters.

What happens when a key is defined more than once?

The last definition wins, matching common dotenv behavior, and the converter displays a warning with both line numbers so the duplicate is not hidden.

Does this tool expand variables such as ${HOST}?

No. It parses values but intentionally does not interpolate variables, execute shell expressions, read files, or contact a server. Expansion behavior differs between dotenv loaders and should be tested in the target runtime.

Sources & references

Primary references: Node.js: DotEnv file format; RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format.

Review policy: references and behavior notes are checked whenever the tool implementation changes.