How to use the env file to json converter
- Paste your env file (KEY=value lines) or a flat JSON object. The box starts with a small example.
- Choose Env file to JSON or JSON to env file. For JSON output, pick whether values are all strings or numbers and booleans, the layout, and whether to sort keys.
- For JSON to env, choose whether to flatten nested keys with underscores and whether to uppercase the names.
- Read the result and the notes about skipped lines or repeated names. Copy it or download it.
What an env file is
An env file holds settings as KEY=value lines, one per line, usually named .env. Lines that start with # are comments, blank lines are ignored, and a line may begin with export. A value can be bare, or wrapped in double quotes or single quotes. Double quoted values understand escapes such as \n and may continue over several lines, and single quoted values are taken literally. In a bare value, a space followed by # starts a comment.
The page reads all of that, so a file like APP_NAME="Sample App", PORT=3000, DEBUG=false and GREETING='Hello $USER' becomes a JSON object with four keys. With all strings selected, PORT is "3000". With numbers and booleans selected, PORT is 3000 and DEBUG is false, while a value such as 02134 stays text so leading zeros are not lost. If a name appears twice, the last value is kept, and the page says so.
From JSON back to an env file
A flat JSON object turns into one KEY=value line per key. Values with spaces, quotes, a hash sign or other special characters are quoted, and a value with a dollar sign is wrapped in single quotes so it stays literal. Null becomes an empty value. Nested objects are flattened with underscores when you allow it, so {"db":{"host":"x","port":5432}} becomes db_host=x and db_port=5432, and with uppercase names, DB_HOST and DB_PORT. Lists cannot be written as a single value, so the page reports them.
Names must start with a letter or underscore and use letters, digits and underscores, and the page refuses anything else with the name of the key. Variables written as ${NAME} are copied as text and not expanded, since expansion depends on the program that reads the file.
Privacy and related tools
Env files often hold secrets such as keys and passwords. This page runs entirely in your browser and nothing is uploaded or stored. Even so, avoid pasting live secrets into any tool you do not need to, and replace them with dummy values when you only want to check the format. After converting, tidy the JSON with the JSON Formatter and Validator, turn it into YAML with the YAML to JSON Converter, or flatten it with the JSON Flatten and Unflatten Tool. The TOML to JSON Converter covers another config format.
Assumptions and limits
- Names use letters, digits, underscores, dots and hyphens and do not start with a digit.
- Variable expansion such as ${NAME} is not performed. Values are copied as written.
- JSON to env needs a flat object, or nested objects with flattening on. Lists are not supported.
- Up to 500,000 characters are read. Nothing is uploaded or stored.
Frequently asked questions
How do I convert a .env file to JSON?
Paste the lines into the box with Env file to JSON selected. Each KEY=value line becomes a key and value in a JSON object, with quotes and comments handled.
Are numbers and booleans converted?
Only if you choose Numbers and booleans. By default every value is a string, which matches how programs read environment variables. A value with leading zeros, like 02134, stays a string either way.
What happens to quoted values?
Double quotes and single quotes are removed. Double quoted values turn escapes such as \n into real characters, and may run over several lines. Single quoted values are kept literally.
Is my data safe to paste?
The conversion runs in your browser and nothing is sent anywhere. Even so, avoid pasting real keys and passwords into any tool if you can use dummy values.