.env to JSON Converter
Convert .env file content to JSON with type inference, nested keys, and # comments linked to the variable right below them. Client-side only.
Paste your .env file content and this tool converts it into JSON instantly in your browser. Numbers and booleans are auto-detected by default (DEBUG=true becomes a real boolean, not the string "true"), dotted keys like DB.HOST become nested objects, and a # comment placed right above a variable moves into a $comments field for that variable. Every option can be switched off. Nothing is uploaded — the conversion runs entirely client-side.
About the .env to JSON Converter
Environment files (.env) are plain KEY=VALUE text, which makes them easy to write but awkward to feed into code that expects structured configuration. This tool parses .env syntax — including # comments, quoted values, and both = and : separators — and produces a JSON object you can drop straight into a config loader, a test fixture, or a debugging session. Three switches control the output: type inference turns numeric and boolean-looking strings into real JSON types, dotted-key nesting turns FEATURE.CACHE.TTL into { "FEATURE": { "CACHE": { "TTL": ... } } }, and comment handling keeps or drops the # lines that documented the original file.
You May Also Need
How to convert .env to JSON
- 1
Paste your .env content
Copy your .env file into the input panel, or click the flask icon for a sample with a comment, a number, and a boolean. Lines may start with export, use = or : between name and value, and wrap values in single or double quotes.
- 2
Adjust advanced options if needed
Open Advanced options to toggle type inference, dotted-key nesting (and its separator), and whether comments are kept as $comments fields or ignored. Defaults match the common convention: types inferred, keys nested, comments kept.
- 3
Click Convert
Each NAME=value line is read in order: a leading export is dropped, and a # comment after the value is removed — a # inside quotes or right after the equals sign stays part of the value. The outer quotes are removed: inside double quotes, \n and \" turn into a line break and a quote, single-quoted text is kept exactly as written, and a quoted value may continue over several lines. # lines directly above a variable are attached to it, and toggling an option afterward re-runs the conversion immediately.
- 4
Copy or download the JSON
Use the copy icon to grab the JSON for pasting elsewhere, or download it as a .json file. Need to go the other way? Use the switch-direction icon to jump to JSON to Env.
References
- The Twelve-Factor App — Config
The widely-cited methodology that popularized storing configuration in environment variables, the convention .env files are built around.
- dotenv (motdotla) — README
The reference implementation and de facto specification for .env file syntax: KEY=VALUE lines, # comments, and quoted values.
- RFC 8259 — The JSON Data Interchange Format
The IETF specification for the JSON format produced by this tool.
Related developer tools
JSON to Env
Convert a JSON object back into .env KEY=VALUE format, with dotted-key flattening and comment reinsertion.
Properties to JSON
Convert a Java .properties file into JSON, with comments above each key kept in a $comments map.
JSON Formatter
Paste raw JSON and instantly get a formatted, syntax-highlighted, validated view.
YAML to JSON
Convert YAML configuration files to JSON and back, another common config format pair.
Env to JSON FAQ
- How do I convert a .env file to JSON online?
- Paste the contents of your .env file into the input panel and click Convert. The tool parses each KEY=VALUE line and outputs a formatted JSON object in the output panel, which you can copy or download as a .json file.
- Does this tool upload my .env file to a server?
- No. Parsing happens entirely in your browser using JavaScript — no network request is made with your file contents, which matters since .env files often hold secrets like API keys and database credentials.
- Does converting .env to JSON keep the comments?
- Comments that describe a variable, yes: one or more # lines immediately above KEY=value go into $comments under that key. A section heading followed by an empty line is not linked to any variable, so it does not show up in the JSON, and empty lines are not recorded either. Choose "Ignore" under Comments in Advanced options to leave every comment out.
- How are boolean and number values handled when converting .env to JSON?
- With Infer types on (the default), exact true and false become JSON booleans and plain decimal numbers such as 5432 become numbers. Values that would change on the way back, like 007 or 1.0, stay strings. Turn Infer types off to keep every value as text.
- Can I turn dotted .env keys into nested JSON objects?
- Yes. With "Dotted keys → nested" enabled (default separator "."), a key like APP.CACHE.TTL=60 becomes { "APP": { "CACHE": { "TTL": 60 } } }. Disable the toggle to keep the original flat dotted key instead.
- What's the difference between .env and JSON for configuration?
- A .env file is a flat list of KEY=VALUE pairs meant for process environment variables (see The Twelve-Factor App's config guidance), while JSON supports nested structures and native types. Converting lets you inspect or diff .env values as structured data, or feed them into tools that only accept JSON.
- What happens if one key is both a value and a parent?
- If the file defines APP=1 and APP.PORT=80 while nesting is on, the converter stops with a key-conflict error instead of silently dropping one of the values. Turn nesting off to keep both as flat keys.