JSON to .env converter

Useful for Docker, Node.js and ASP.NET when moving JSON settings into environment variables. The __ separator is what ASP.NET Core uses for levels.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter json text, level separator and upper_case names.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Key paths are joined with the chosen separator, so database.host becomes DATABASE__HOST and list items become LIST__0. Any character other than Latin letters, digits and _ becomes _. Simple values are written as they are, values with spaces or symbols go in single quotes, and values with line breaks go in double quotes with \n.

Example

Inputs: Level separator = Double underscore __, UPPER_CASE names = yes. Result: .env: APP=toolsahla VERSION=2.1.0 PORT=8080 DEBUG=false LANGUAGES__0=ar LANGUAGES__1=en DATABASE__HOST=localhost DATABASE__USER=admin DATABASE__TIMEOUT=30 ; Variables: 9.

{
  "app": "toolsahla",
  "version": "2.1.0",
  "port": 8080,
  "debug": false,
  "languages": ["ar", "en"],
  "database": {
    "host": "localhost",
    "user": "admin",
    "timeout": 30
  }
}
APP=toolsahla
VERSION=2.1.0
PORT=8080
DEBUG=false
LANGUAGES__0=ar
LANGUAGES__1=en
DATABASE__HOST=localhost
DATABASE__USER=admin
DATABASE__TIMEOUT=30

Limits and caveats

  • Every value becomes text, since environment variables are text.
  • Some tools such as Docker Compose expand $ inside double quotes, so check values that contain $.

Questions about this tool

When should I pick __ over _?

Pick __ when keys already contain _, so levels stay distinct from names. It is also the ASP.NET Core convention.

Why do I get "both become" errors?

Two keys such as a-b and a_b both turn into A_B. Rename one of them in the JSON.

How is null written?

As an empty value such as KEY=, since environment variables have no null.