JSON to .env Converter
Convert JSON to .env format: nested keys flattened to UPPER_SNAKE_CASE, values quoted and escaped when needed, optional export prefix. Free and local.
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is JSON to ENV?
Turn a JSON object into .env lines. Nested objects and arrays are flattened with underscores, keys can be normalized to UPPER_SNAKE_CASE, and values that contain spaces, quotes, #, $ or line breaks are wrapped in double quotes with escapes.
How to use JSON to ENV
- Paste JSON into the JSON input box, or use Load sample or Open file.
- Toggle UPPER_SNAKE_CASE keys, Prefix lines with export and Quote every value.
- The .env output updates as you type; use Copy or Download.
Example
{"dbHost":"localhost","db":{"port":5432},"msg":"hi there"} DB_HOST=localhost DB_PORT=5432 MSG="hi there"
When to use JSON to ENV
Use it to create .env files from JSON config, secrets exports or CI variables. Large nested structures produce long variable names; consider keeping such data as a single JSON string variable instead.
How JSON to ENV works
The object is flattened with _ as separator (arrays by index). Key normalization splits camelCase, replaces invalid characters with _ and upper-cases the result (dbHost → DB_HOST). Values are converted to strings (null becomes empty) and quoted only when needed; inside double quotes, backslashes, quotes, newlines and tabs are escaped so dotenv reads the exact value back.
Common Use Cases
- Create a .env file from a JSON config template
- Turn exported cloud secrets JSON into environment variables
- Prepare variables for Docker or docker-compose
- Convert app settings into CI/CD variables
FAQs
How are nested objects named?
Keys are joined with underscores: {"db":{"port":5432}} becomes DB_PORT=5432.
When are values quoted?
Only when they contain whitespace, quotes, #, $, =, a backslash, or leading/trailing spaces – or always if you enable Quote every value.
Can the output be read back?
Yes, the ENV to JSON tool (and dotenv) parses it back to the same string values.