Dotenv to JSON Converter
Convert a .env file into a JSON object — and back from JSON to .env. Parses export prefixes, quoted values and inline comments; optional nested JSON (split keys by __), alphabetical key sorting and dropping empty values. Runs entirely in your browser.
Input
Options
APP__NAME becomes { "APP": { "NAME": ... } }.
Output
Guides
Convert a .env file into a clean JSON object — or turn a JSON config back into .env format — right in your browser. Paste your environment variables, pick a direction, and copy or download the result. Nothing is uploaded; the conversion runs entirely on your device.
What it does
Environment files (.env) and JSON are the two most common ways to store configuration, but they don't interchange cleanly by hand. This tool bridges them both ways:
.env→ JSON parses eachKEY=valueline into a JSON object. It understandsexportprefixes, single- and double-quoted values (including values that span multiple lines), and trailing# inline comments.- JSON →
.envflattens a JSON object back intoKEY=valuelines, joining nested keys with an underscore and automatically quoting any value that contains spaces,#,=, quotes, or newlines.
How to use it
- Choose a Direction:
.env → JSONorJSON → .env. - Paste your content into the Input box (or click Try an example).
- Adjust the options if you need them.
- Copy the output or download it as a file.
Options
- Nested JSON (split keys by
__) — when converting.envto JSON, a key likeAPP__NAMEbecomes{ "APP": { "NAME": ... } }, so double underscores turn flat keys into a nested structure. - Sort keys alphabetically — orders the output keys, making diffs and reviews easier to read.
- Exclude empty values — drops any key whose value is an empty string.
FAQ
How are quoted values handled?
Surrounding single or double quotes are stripped from .env values, so DB_PASS="s3cret value" becomes "s3cret value" in JSON. When converting back to .env, values that contain spaces or special characters are re-wrapped in double quotes, with internal quotes, backslashes, and newlines escaped.
What happens to comments?
Full-line comments (lines starting with #) and blank lines are ignored. A trailing inline comment such as CACHE_TTL=3600 # seconds is stripped from the value, leaving 3600.
Does it support nested JSON both ways?
Yes. .env → JSON can rebuild nesting from __-separated keys, and JSON → .env flattens nested objects by joining levels with a single underscore (e.g. { "db": { "host": "…" } } becomes db_host=…).
What if my JSON is invalid?
The output shows a short error comment (for example, # Error: Invalid JSON input) instead of a result, so you can fix the input and try again. Arrays and primitives aren't valid top-level values — the input must be a JSON object.
Privacy
Everything happens locally in your browser. Your .env contents — including any secrets, API keys, or database passwords — are never sent to a server. For extra safety, the input is deliberately kept out of any shareable link, so only your chosen options are shared, never the pasted content.
Use it from code
From 3 credits per callREST API
curl -X POST https://api.iotools.cloud/v1/tool/dotenv-to-json-converter \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"conversionDirection": "env-to-json",
"input": "# Database Configuration\nDB_HOST=localhost\nDB_PO…",
"nestedJson": "",
"sortKeys": "",
"excludeEmpty": ""
}'Swap in your own key from your account. The tool's fields are the body — no wrapper.
Ask an AI agent
Use the IOTools `dotenv-to-json-converter` tool (Dotenv to JSON Converter) on this input:
YOUR_INPUT_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.