consolelog.tools

ENV to JSON Converter

Convert a .env file into flat or nested JSON, YAML, a typed TypeScript interface, a NodeJS.ProcessEnv declaration, a docker-compose environment block, a Kubernetes ConfigMap, or a shell export script — and back to .env from JSON. The parser handles export prefixes, quoted and multiline values, and inline comments; a validation panel flags duplicate keys, illegal names and detected secrets, with one-click masking for safe sharing.

About this ToolHow it works, benefits & use cases

A .env file is just KEY=value lines, but real-world ones carry export prefixes, single- and double-quoted values with escapes, multiline values, blank lines, and inline # comments. This converter parses all of that robustly and then re-emits your variables in whatever shape the next step needs. From a .env file it can produce flat JSON, nested JSON (splitting keys on __ or .), YAML, a typed TypeScript interface, a NodeJS.ProcessEnv declaration, a docker-compose environment block, a Kubernetes ConfigMap, or a shell export script. It also runs in reverse, flattening a JSON object back into a normalized .env. A coerce-types toggle turns true/false, numbers and null into real typed values, a mask-secrets toggle obscures any value whose key looks like a secret or token so output is safe to share, and a live validation panel flags duplicate keys, illegal variable names, unescaped quotes, and the number of detected secrets. Everything runs in your browser, so the contents of your .env never leave your machine.

How to Use

  1. 1Pick a direction: ".env to target" to convert a .env file, or "JSON to .env" to go the other way.
  2. 2Paste your .env content or JSON object into the input panel, or click "Load example" to drop in a sample for the current direction.
  3. 3In ".env to target" mode, choose an output format: flat JSON, nested JSON, YAML, TypeScript interface, NodeJS.ProcessEnv, docker-compose, Kubernetes ConfigMap, or shell export script.
  4. 4Toggle "Coerce types" to turn true/false, numbers and null into typed values instead of plain strings.
  5. 5Toggle "Mask secrets" before sharing to obscure values whose key looks like a secret, token, password, or key.
  6. 6Read the live output in the sticky panel and check the validation card, then copy, download, or share the result via URL.

Key Benefits

  • Robust parser handles export prefixes, quoted and multiline values, escapes, and inline # comments
  • Eight output targets from one .env: flat JSON, nested JSON, YAML, TypeScript interface, NodeJS.ProcessEnv, docker-compose, Kubernetes ConfigMap, and shell export script
  • Nested mode splits underscore (__) or dot-delimited keys into a structured object
  • Reverse direction flattens a nested JSON object back into a normalized .env file
  • Optional type coercion converts true/false, numbers and null into real typed values
  • Secret masking obscures sensitive values so output is safe to paste into a ticket or chat
  • Live validation panel flags duplicate keys, invalid names, unescaped quotes, and counts detected secrets
  • Runs entirely in the browser and the output is shareable via URL or pipeable into other tools

Common Use Cases

  • Importing a .env file into application config as a flat or nested JSON object
  • Generating a typed TypeScript interface or NodeJS.ProcessEnv declaration from your environment variables
  • Producing a docker-compose environment block or a Kubernetes ConfigMap from an existing .env
  • Creating a shell export script to source the same variables in a terminal session
  • Converting a JSON config block back into a .env file for local development
  • Auditing a .env for duplicate keys, illegal names, and accidentally committed secrets

10 variables · JSON (flat)

{
  "NODE_ENV": "production",
  "PORT": 3000,
  "DEBUG": false,
  "DATABASE__HOST": "localhost",
  "DATABASE__PORT": 5432,
  "DATABASE__NAME": "my app db",
  "API_KEY": "sk_live_5f3c9a1b2d4e6f8a",
  "JWT_SECRET": "super-secret-value",
  "WELCOME_MSG": "Hello, \"world\"!",
  "RETRIES": 5
}
A couple of notes
  • Value of "WELCOME_MSG" contains an unescaped double-quote.
  • 2 values look like secrets — enable masking before sharing.

Conversion

Turn true/false, numbers and null into typed values instead of strings.

Obscure values whose key looks like a secret/token/password/key.

Paste your .env file. Supports export, quotes, multiline values and comments.

More than a JSON dump

A .env file is just KEY=value lines, but real files carry export prefixes, quoted and multiline values, and inline # comments. This converter parses all of that, then re-emits it in whatever shape you need next — flat or nested JSON (keys split on __ or .), YAML, a typed TypeScript interface, a NodeJS.ProcessEnv declaration, a docker-compose environment block, a Kubernetes ConfigMap, or a shell export script.

What the validator checks

  • Duplicate keys — where the last value silently wins.
  • Names that are not legal env identifiers.
  • Values with unescaped quotes that would break parsing.
  • A count of values that look like secrets, with one-click masking before you share.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools