ENV to JSON Converter — Dotenv ↔ JSON | GadgetSurge

Convert .env to JSON or JSON to .env with export stripping and quote rules. Warnings for duplicates. Runs in your browser — secrets stay local.

About ENV to JSON Converter

.env files use KEY=value lines. Blank lines and lines starting with # are comments. A leading export prefix is stripped. Only the first = splits key and value. Matching quotes are removed; double-quoted values turn \n into real newlines, while single-quoted values stay literal in most dotenv parsers.

Different libraries treat quotes differently, which matters in Docker: docker run --env-file often keeps quotes as part of the value, while Docker Compose v2 .env interpolation may strip them — a common source of “my API key has quotes in it” bugs.

Never commit .env files with secrets. Use .env.example with the same keys and empty or placeholder values. Hosting dashboards on Vercel and Netlify accept pasted KEY=value blocks; JSON is handy for secret managers and CI variable JSON imports.

JSON → .env requires a flat object only. Nested objects or arrays trigger an error naming the offending key. Values with spaces, #, =, or newlines are double-quoted with escaped newlines.

Warnings appear separately so the output stays clean for copy-paste. Processing runs entirely in your browser.

How to Use ENV to JSON Converter

  1. Paste a .env file or flat JSON object into the input area.
  2. Check the direction badge (.env → JSON or JSON → .env) and click Swap direction if needed.
  3. Review warnings for duplicate keys, invalid names, or lines that could not be parsed.
  4. Copy or download the output; enable Mask values when presenting on a shared screen.

Common Use Cases

Frequently Asked Questions

How is direction detected?

If the trimmed input starts with {, it is treated as JSON → .env. Otherwise it is parsed as .env → JSON.

What happens with duplicate keys?

The last value wins. Warnings list each line number where the key appeared.

Are nested JSON objects supported?

No. Nested objects and arrays return an error that names the key that must be flattened.

Does Docker strip quotes?

docker run --env-file typically does not strip quotes; Compose v2 handling often does. Always verify in your target environment.

What keys are valid?

This tool warns when keys do not match ^[A-Za-z_][A-Za-z0-9_]*$, which matches common dotenv conventions.

Does mask affect downloads?

Mask replaces values with •••• in the display and in copy/download when enabled — use it only when you intend to hide secrets.

Is export supported?

Yes. A leading export on a line is stripped before parsing KEY=value.

Is my .env uploaded?

No. Parsing runs entirely in your browser.