ENV to JSON ConverterParse .env Files, Quotes & Comments

Paste a .env file and get a JSON object, or paste JSON and get a .env file. Quotes, comments, multiline values, and number or boolean types are handled for you.

Your input is never sent anywhere.

Details
Input .env
Output JSON
Your result appears here

Careful .env parsing

Quotes, export lines, multiline values, and inline comments.

Both directions

Convert .env to JSON and JSON back to .env.

Runs in your browser

Your input is not sent anywhere.

Usage Tips

  • Blank lines and lines that start with # are skipped. In an unquoted value, a # after a space starts a comment.
  • Quote a value to keep a # or surrounding spaces. Double quotes turn \n into a new line, and single quotes keep every character as typed.
  • Quoted values always stay strings. Type inference only applies to unquoted values.
  • References such as ${HOST} are kept as text and are not expanded.

How to convert a .env file to JSON

Paste the contents of a .env file and you get a JSON object with one key per variable. The parser follows the rules most dotenv libraries share. It skips comments and blank lines, accepts an export prefix, reads quoted values, and splits each line at the first equals sign.

Unquoted values that are plain numbers, or true, false, or null, can be turned into JSON types. Quoted values always stay strings. If a line cannot be read, such as one with no equals sign, the tool skips it and lists it under the editor instead of failing silently.

Switch to JSON → env to go the other way. It accepts an object or an array of name and value pairs, and it puts quotes around values that contain spaces, hash signs, or quotes.

When you need .env data as JSON

A config or API that expects JSON

Paste a .env file and copy the object. Use it as a settings file, a request body, or test data without retyping each key.

ECS container environment

Amazon ECS describes container variables as name and value pairs. Pick the name/value array format and paste the result into the environment list.

A .env file that will not load

See exactly how each line parses. Skipped lines, missing quotes, and duplicate keys are listed under the editor with their line numbers.

A .env file made from JSON

Turn a JSON object or a list of name and value pairs into KEY=VALUE lines, with quoting added where a value needs it.

Convert in 4 steps

  1. Choose env → JSON to read a .env file, or JSON → env to write one.
  2. Paste your data into the input box. The result updates as you type.
  3. Set the options. For JSON output you can pick the format, the indent, type inference, and key sorting.
  4. Click Copy, or Download to save config.json or .env.

Note: Lines the tool skips, and the reason for each, are listed under the editor. The result is still produced for the lines it could read.

How each line is parsed

  • Lines: blank lines and lines that start with # are skipped. An export prefix is removed, so export HOST=localhost reads as HOST.
  • Splitting: each line is split at the first equals sign. Anything after it, including more equals signs, belongs to the value.
  • Unquoted values: the value is trimmed. A # that follows a space starts a comment, and a # with no space before it stays in the value.
  • Quoted values: double quotes convert \n, \r, \t, \\, and \". Single quotes and backticks keep every character as typed. All three can run over several lines. Text after the closing quote is ignored, apart from a comment.
  • Type inference: only unquoted values are checked. True, false, and null are matched without regard to case. A number is converted only if it prints back exactly as typed, so 007, 1.10, and 0x1F stay strings.
  • Variable references: ${NAME} and $NAME are not expanded.
  • Duplicates and order: when a key appears twice, the last value is used and a notice is shown. Keys keep the order of their first appearance unless Sort keys is on.

How .env values map to JSON

Examples of what each kind of line becomes with Infer types on.

Line in .envHow it is readResult in JSON
PORT=3000Unquoted plain number3000 (number)
DEBUG=trueUnquoted booleantrue (boolean)
API_KEY="abc123"Quoted values stay strings"abc123" (string)
ZIP=02134Leading zero, so not a plain number"02134" (string)
GREETING="Hello\nWorld"Double quotes turn \n into a line break"Hello\nWorld"
NOTE='C:\temp'Single quotes keep characters as typed"C:\\temp"
URL=https://example.com/a?b=1#top# with no space before it is part of the valueThe whole URL
NAME=Joe # admin# after a space starts a comment"Joe"
export HOST=localhostThe export prefix is removed"HOST": "localhost"
EMPTY=Empty value"" (empty string)

Why parsers disagree. There is no formal spec for .env files. Quoting, inline comments, and multiline values are handled a little differently by Node.js, Python, Ruby, Go, and Docker Compose. This tool follows the rules they have in common. For a value that must read the same everywhere, quote it and use \n escapes instead of real line breaks.

Keep secrets in mind. The conversion happens in your browser and nothing is uploaded. If you only need the shape of a file, replace real keys and passwords with placeholders before you paste.

Where .env values end up: Vercel, ECS, Docker, and plain JSON

A few places where the format of your variables decides whether they load.

Vercel can take a pasted .env file directly

To add many variables to a Vercel project, you can paste the contents of a .env file into the Environment Variables form or upload the file. No JSON step is needed for that.
Convert to JSON when the destination asks for JSON, such as a config file, an API request, or a tool that reads an object.

ECS lists variables as name and value pairs

In an Amazon ECS container definition, the environment is a list of name and value pairs, and both parts are strings. The Name/value array format produces that shape.
Because every value must be a string, the tool turns off type inference for this format, so 3000 stays as the text 3000.

Comments, quotes, and the $ sign

Docker Compose requires a space before # for an inline comment on an unquoted value, so VAR=VAL# text keeps the whole string. This tool uses the same rule. Quote any value that contains a # to be safe.
Compose also expands $ references in unquoted and double-quoted values and leaves single-quoted values as typed. A password that contains $ is safest in single quotes.

Private keys and other multiline values

Real line breaks inside quotes work in Node.js, Python, Ruby, and Go, but Docker Compose env files do not support them. The \n escape inside double quotes works in all of them.
This tool reads both forms. In the JSON output, line breaks always appear as \n, which is valid in any JSON string.

Where .env conversions go wrong

A port or flag arrives as the wrong type

Everything in a .env file is text, so a plain conversion gives you "3000" and "false". Code that compares with a number or a boolean then fails in ways that are hard to trace. Converting everything blindly causes the opposite problem: an ID like 007 turns into 7.

💡 See the solution▼
Leave Infer types on to get 3000 and false as real JSON types. Put quotes around any value that must stay text. A value with a leading zero, or a number that would not print back exactly as typed, is kept as a string anyway.

A # in a password cuts the value short

A line such as DB_PASS=abc #123 is read as the value abc with a comment after it. The password is truncated, and the error only shows up when the app fails to log in.

💡 See the solution▼
Quote the value: DB_PASS="abc #123". A # inside quotes is always kept. A # with no space before it, as in abc#123, is part of the value even when unquoted.

A multiline private key breaks the file

A key that is pasted with real line breaks and no quotes is read as one line per variable, and everything after the first line is lost or misread. Some platforms also reject real line breaks in an env file.

💡 See the solution▼
Put the value in double quotes. Real line breaks and \n escapes both work here, and the JSON output uses \n. For files that other tools will read, prefer the \n form.

A line is ignored and you never find out

A typo like API_KEY abc123, with no equals sign, is skipped by many parsers without any message. The variable is just missing at runtime.

💡 See the solution▼
This tool lists every skipped line with its number under the editor, along with duplicate keys and missing closing quotes. Check that panel before you copy the result.

ENV and JSON converter FAQ

Q.How do I convert a .env file to JSON?

Q.

A. Select env → JSON, then paste the contents of your .env file into the input box. The JSON object appears on the right as you type, with one key per variable. Click Copy or Download to take it with you. Comments and blank lines are skipped, and an export prefix on a line is removed.

Q.Why are some values numbers or booleans and others strings?

Q.

A. With Infer types on, an unquoted value that is a plain number, true, false, or null becomes that JSON type, so PORT=3000 gives 3000 and DEBUG=true gives true. Quoted values always stay strings, and so do numbers that would not print back exactly as typed, such as 007, 1.10, or 1e3. Turn Infer types off to get strings everywhere.

Q.How are comments handled?

Q.

A. A line that starts with # is skipped. In an unquoted value, a # that comes after a space starts a comment, so NAME=Joe # admin gives Joe. A # with no space before it stays part of the value, and a # inside quotes is always kept. This matches the rule in the Docker Compose documentation.

Q.Does it handle multiline values like private keys?

Q.

A. Yes. A value in double quotes can continue over several lines, or it can use \n escapes on one line. Both give the same string. Single-quoted and backtick-quoted values can span lines too, but they are read exactly as typed. In the JSON output, line breaks appear as \n.

Q.Can I convert JSON back to a .env file?

Q.

A. Yes. Select JSON → env and paste an object, or an array of name and value pairs. Nested objects and arrays are written as JSON text. Values that contain spaces, a # sign, or quotes are put in quotes so they read back correctly.

Q.Does it expand variable references like ${HOST}?

Q.

A. No. A reference such as ${HOST} or $HOST is kept as plain text in the JSON. Some tools expand these when they load a file, for example Docker Compose in unquoted and double-quoted values, but this converter only reads what is written in the file.

Q.What is the name/value array format for?

Q.

A. Some services describe environment variables as a list of name and value pairs rather than one object. Amazon ECS container definitions do this, for example. Choose Name/value array to get that shape. The values in this format are always strings, so type inference is switched off.

Q.What happens to lines the tool cannot read?

Q.

A. They are skipped, and a notice under the editor tells you which line and why. This covers a line with no equals sign, an empty or invalid key, a missing closing quote, and duplicate keys, where the last value wins. Nothing is dropped without a message.

Q.Is my .env content sent to a server?

Q.

A. No. The conversion runs as JavaScript in your browser, and the tool has no upload step. Your text is held only in the page while it is open, and closing or reloading the page clears it. If you only need the structure of a file, you can still swap real secrets for placeholder values before you paste.

User Feedback & Request

Your feedback
makes this tool better.

Tell us which features you'd like, what should be fixed, or which new tool you'd like to see. An engineer reads every submission and uses it to guide development.

Send feedback