ENV to JSON
Convert a .env file into JSON or YAML. Comments, blank lines and export prefixes are skipped, quoted values are unquoted, and escapes such as \n in double quotes become real line breaks. Optionally turn true, false, null and plain numbers into JSON types instead of strings.
Frequently asked questions
Which .env syntax is supported?
The common dotenv syntax: KEY=value lines, an optional export prefix, comments starting with #, inline comments after a space and #, single, double and backtick quotes, and quoted values that span several lines.
How are quotes and escapes handled?
Single quoted and backtick quoted values are taken literally. In double quoted values, \n, \r, \t, \" and \\ are decoded. Unquoted values are trimmed and end at an inline comment.
Are variables such as ${HOME} expanded?
No. References are kept as written, because their values depend on the environment where the file is loaded. The ENV Checker reports references to variables the file does not define.
What happens with duplicate keys?
The last value wins, which is how dotenv parses a file. Use the ENV Checker to find duplicates before converting.
What does the types option do?
Without it every value is a string, as environment variables always are. With it, true, false and null become JSON literals, and plain numbers such as 8080 or 0.5 become numbers. Values with leading zeros stay strings.
Why is my file rejected?
A line without an equals sign, a key with characters other than letters, digits, dots, dashes and underscores, or a quote that is never closed stops the conversion, and the message names the line.