Skip to main content

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

Output
 
Was this helpful?

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 each KEY=value line into a JSON object. It understands export prefixes, single- and double-quoted values (including values that span multiple lines), and trailing # inline comments.
  • JSON → .env flattens a JSON object back into KEY=value lines, joining nested keys with an underscore and automatically quoting any value that contains spaces, #, =, quotes, or newlines.

How to use it

  1. Choose a Direction: .env → JSON or JSON → .env.
  2. Paste your content into the Input box (or click Try an example).
  3. Adjust the options if you need them.
  4. Copy the output or download it as a file.

Options

  • Nested JSON (split keys by __) — when converting .env to JSON, a key like APP__NAME becomes { "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.

dotenvenvjsonconverterconfigenvironment-variablesdevops

Use it from code

From 3 credits per call

REST 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_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.