How to Convert a .env File to JSON (and Back)

Updated 2026-06-21

To convert a .env file to JSON, paste your KEY=VALUE config into a converter, choose the .env → JSON direction, and copy the flat JSON object it produces. The .env ⇄ JSON Converter does this live as you type — and because it runs entirely in your browser, your keys and secrets never leave your machine.

Why convert between .env and JSON

A .env file stores configuration as plain KEY=VALUE lines, which is perfect for shell tooling and dotenv loaders. But many setups need the same values as JSON instead: seeding a config object in code, pasting variables into a CI dashboard, building a Kubernetes ConfigMap, or reviewing settings as structured data. Converting the other way — JSON back to .env — is just as common when a service hands you a JSON blob and your local app expects a dotenv file. Doing it by hand invites typos in exactly the place you least want them.

Convert a .env file to JSON

  1. Open the converter and pick .env → JSON with the segmented control at the top.
  2. Paste your file into the left input box. Conversion runs automatically — there is no submit button.
  3. Read the JSON on the right and check the Pairs stat to confirm how many key/value pairs were produced.
  4. Click Download to save env.json, or Copy. You can also select part of the output to copy just one key.

The parser understands real-world dotenv syntax: an optional export prefix, full-line # comments, blank lines, and both single quotes (raw) and double quotes (with escape handling). When a key repeats, the later value wins. Malformed lines — no equals sign, an empty key, or an invalid name — are skipped and reported with their line numbers instead of silently corrupting the output.

Convert JSON back to .env

Switch the direction to JSON → .env and paste a JSON object. Optionally turn on Prefix with export to emit export KEY=VALUE lines for shell sourcing.

One rule matters here: the JSON must be a flat object whose values are strings, numbers, booleans, or null. Arrays, nested objects, and non-finite numbers have no .env representation, so the tool shows a clear error rather than producing garbage. Values that need protecting — whitespace, quotes, a #, or newlines — are automatically double-quoted and escaped so they round-trip back cleanly.

The privacy advantage

A .env file is the single most sensitive text file in most projects: database passwords, API keys, signing secrets. Pasting that into a random online converter means uploading your secrets to someone else's server. This tool parses everything locally in your browser — nothing is uploaded, there is no signup, and no account is required. Input is capped at about 1 MB so per-keystroke conversion stays instant.

Ready to convert? Open the .env ⇄ JSON Converter and paste your config — your keys stay on your machine.

Try the .env ⇄ JSON Converter →