.env โ JSON
Turn a .env file into JSON, or JSON into .env, Compose, docker flags or a ConfigMap, with quoting done right.
Moving configuration between .env, JSON and Kubernetes
The same configuration lives in many shapes: a .env file for local development and Docker Compose, a JSON file for a framework, docker run -e flags in a script, a Kubernetes ConfigMap in the cluster. Converting between them by hand invites typos and quoting bugs, particularly with values that contain spaces, quotes, # or line breaks.
Paste a .env file to get JSON, optionally nesting keys that use double underscores. Paste a JSON object to get a .env file, a Docker Compose environment block, docker run flags or a Kubernetes ConfigMap. Nested objects and arrays are flattened into upper-case names joined by __, and values are quoted exactly when they need to be, so the result loads back unchanged.
Rules the parser follows
- Blank lines and lines beginning with
#are ignored; an unquoted value stops at#preceded by a space. - Double quotes may span several lines and understand
\n,\t,\"and\\. - Single quotes are taken literally, including any
#or$. - Variable names must start with a letter or underscore.
Variable expansion ($OTHER) is not performed, since each tool implements it differently. Keep secrets out of files you commit, and use a secret manager for production. Conversion happens locally in your browser.
Frequently asked questions
What is the format of a .env file?
One KEY=value per line. Lines starting with # are comments, an optional export prefix is allowed, and values with spaces or special characters go in quotes. Double-quoted values process escapes such as \n; single-quoted values are literal.
How are nested JSON objects represented?
They are flattened with double underscores: {"db":{"host":"h"}} becomes DB__HOST=h. The double underscore is the convention used by .NET configuration and many 12-factor tools, and it can be turned back into nesting.
Should I commit a .env file?
No. Commit a .env.example with placeholder values and keep the real file out of version control. Anything in a committed .env should be treated as public.
What is the ConfigMap output for?
Kubernetes ConfigMaps hold non-secret configuration as key-value data. The output is a ready ConfigMap manifest. Put passwords and tokens in a Secret instead.