Skip to content
UniKit

.env to JSON

Convert .env files to JSON and back: export prefixes, single and double quotes, trailing comments, blank lines, equals signs inside values, backslash line continuations and multi-line quotes — with duplicate-key warnings and line/key counts.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Result

What this tool does

  • Turn .env / .env.local into JSON so scripts, CI jobs and docs can read the same variable names and values.
  • Write a JSON config out as .env for runtimes that only consume environment variables, such as Docker Compose or PM2.
  • Debug "my variable is not applied": spot stray spaces, unexpected quoting or values cut off by a trailing comment.

Example

Input

export API_URL=https://example.com
TOKEN="a b c"
EMPTY=

Output

{
  "API_URL": "https://example.com",
  "TOKEN": "a b c",
  "EMPTY": ""
}

Single quotes stay literal, double quotes expand \n and \t escapes, and unquoted values drop trailing comments.

Frequently asked questions

Do values with spaces need quotes?

Prefer quotes. FOO=a b parses to a b (same as dotenv), but trailing spaces in unquoted values are easily stripped by editors or CI, so "a b" is safer.

Which value wins when a key is defined twice?

The last one, matching how source behaves in a shell. Duplicated key names are listed under the result so you can clean them up.

Are multi-line values supported?

Yes. An unquoted value ending with a backslash continues on the next line (the line break becomes a real newline), and a double-quoted value may span lines until the quote closes.

How are arrays and nested objects handled when converting JSON to .env?

Arrays of scalars are joined with commas, so ["a","b"] becomes KEY=a,b. Nested objects cannot be expressed in .env and raise an error.

Keywords:envdotenv.envenv to jsonjson to envenv 转 json环境变量environment variablesdotenv 解析convert

Related tools