How to use the env to json converter
- Paste your
.envfile contents or typeKEY=valuepairs into the input area. - Adjust the indent size if you prefer compact or expanded JSON formatting.
- The JSON output updates automatically as you type or paste.
- Copy the resulting JSON for use in configuration files, APIs or scripts.
How env to json conversion works
The parser reads the input line by line. Lines starting with # are treated as comments and skipped. Blank lines are ignored. Each remaining line must contain an equals sign separating a key from its value. If a line begins with export , that prefix is stripped before parsing.
Values wrapped in double quotes (") or single quotes (') have those quotes removed, and the inner text is kept exactly as written. Double-quoted values process standard escape sequences like \n, \t, \\ and \". Single-quoted values are taken literally. Unquoted values are trimmed of surrounding whitespace, and anything after an unquoted # preceded by a space is treated as an inline comment.
After extracting the raw string, the converter attempts to cast it to a JSON primitive. The strings true and false become booleans. Strings that match integer or decimal patterns (like 42 or 3.14) become numbers, but only when the number prints back exactly as typed, so 1.10 and very long ids stay as strings. Everything else remains a JSON string. For example, given PORT=8080 and DEBUG=true, the output is {"PORT": 8080, "DEBUG": true}.
Common .env syntax rules
Different runtimes parse .env files slightly differently, but most follow conventions established by the original dotenv libraries. Here is a reference table of how this converter handles common patterns:
| Input | JSON Value | Notes |
|---|---|---|
KEY=value | "value" | Simple unquoted string |
KEY="hello world" | "hello world" | Double quotes removed |
KEY='hello world' | "hello world" | Single quotes removed, no escape processing |
KEY=123 | 123 | Parsed as number |
KEY=true | true | Parsed as boolean |
KEY= | "" | Empty string |
KEY="line1\nline2" | "line1\nline2" | Escape sequence preserved in JSON |
# comment | (skipped) | Full-line comment |
KEY=val # note | "val" | Inline comment stripped |
When to convert environment variables to JSON
Many modern tools and deployment pipelines expect configuration in JSON format rather than flat key-value pairs. Converting env to json is useful when migrating a project from a simple .env setup to a structured configuration file consumed by services like AWS Parameter Store, Docker config files or Kubernetes ConfigMaps.
Frontend build tools sometimes need environment variables injected as a JSON object at build time. Instead of manually rewriting each variable, you can paste the entire .env file through this converter and embed the result directly into your build script. This approach also helps when sharing sanitized configuration examples with teammates who need a quick JSON representation of required keys.
Edge cases and common mistakes
One frequent mistake is forgetting that unquoted values containing spaces will be trimmed. If your value has leading or trailing spaces that matter, wrap it in double or single quotes. Another issue arises with hash symbols inside unquoted values: URL=http://example.com#section will keep the fragment because there is no space before the #, but COLOR=#fff # white will strip everything after the first spaced hash.
Duplicate keys are resolved by keeping the last occurrence, matching the behavior of most dotenv parsers. Keys themselves are not modified beyond stripping the optional export prefix; they remain case-sensitive. If you need to reformat or sort your environment variables before converting, you can use the env formatter first.
For other configuration formats, similar converters exist. You can transform INI to JSON, TOML to JSON, Java properties to JSON or query strings to JSON using dedicated tools on this site.
Security considerations
Environment files frequently contain sensitive credentials such as database passwords, API tokens and private keys. Because this tool processes everything locally in your browser, no data is transmitted over the network. However, you should still avoid pasting production secrets into any online tool on shared or compromised machines.
If you need to share a configuration template with others, replace real secrets with placeholder values before running the env to json conversion. This keeps your actual credentials safe while still providing a valid JSON structure for documentation or testing purposes.
Worked examples
| Example | Input | Result |
|---|---|---|
| Database configuration | ENV input: DB_HOST=localhost / DB_PORT=5432 / DB_NAME=myapp / DB_USER=admin / DB_PASS="s3cret!" | { / "DB_HOST": "localhost", / "DB_PORT": 5432, / "DB_NAME": "myapp", / "DB_USER": "admin", / "DB_PASS": "s3cret!" / } |
| Booleans and numbers | ENV input: DEBUG=true / MAX_RETRIES=3 / TIMEOUT=30.5 / VERBOSE=false | { / "DEBUG": true, / "MAX_RETRIES": 3, / "TIMEOUT": 30.5, / "VERBOSE": false / } |
| With comments and blank lines | ENV input: # App settings / APP_NAME="My App" / # Server port / PORT=8080 # default port | { / "APP_NAME": "My App", / "PORT": 8080 / } |
FAQ
Does this converter upload my .env data to a server?
No. The conversion happens entirely in your browser using JavaScript. Your environment variables never leave your device.
How are quoted values handled?
Double-quoted values have their quotes removed and standard escape sequences processed. Single-quoted values have their quotes removed but are otherwise treated as literal strings.
Will numbers and booleans stay as strings?
No. Unquoted values that look like numbers (such as 42 or 3.14) or booleans (true, false) are converted to their corresponding JSON types. Quoted values always remain strings.
What happens if a line has no equals sign?
Lines without an equals sign that are not comments or blank will cause an error. Every variable definition must follow the KEY=value format.
Can I convert the JSON back to .env format?
This tool only converts in one direction. To format or clean up existing .env files, use the env formatter.
Are duplicate keys allowed?
Yes. If the same key appears multiple times, the last value wins, which matches the behavior of most dotenv libraries.
Does it support the export keyword?
Yes. Lines starting with export followed by a space are parsed normally after stripping the export prefix.