Skip to content
ToolBoxGeniehome

ENV and INI to JSON

Developer Tools · Added

Three formats that look interchangeable and are not: .env has no specification and follows what dotenv does, .ini adds sections, and .properties has a written standard with rules the other two do not share. This reads all three properly and writes them back.

Direction

KEY=value, as dotenv and the shell read it

JSON

Keys
4
Comments
1

Dropped — JSON has nowhere to put them

{
  "DATABASE_URL": "postgres://localhost:5432/app",
  "API_KEY": "abc123",
  "DEBUG": "false",
  "TIMEOUT": "30"
}

Keys and values

KeyValue
DATABASE_URLpostgres://localhost:5432/app
API_KEYabc123
DEBUGfalse
TIMEOUT30

1 comment line was dropped. JSON has no comment syntax, so the round trip works and the explanations do not survive it — worth knowing before replacing a documented config file with generated output.

Values stay strings unless you ask otherwise, and that default is deliberate: an environment variable is a string to the process that reads it, so turning 0755 into the number 755, or false into a boolean, changes what the setting means. Everything here runs in your browser — worth knowing, since a real .env file usually holds credentials.

How to use the env and ini to json

  1. 1Choose the format of the file you have — the hint under the selector says what makes each one different.
  2. 2Paste the file. Comments, quoting and section headings are all handled.
  3. 3Read the JSON, or the key table beneath it if you are checking one setting.
  4. 4Switch the direction to generate a config file from JSON instead.

Examples

A .env with quoting

Input
DATABASE_URL="postgres://localhost:5432/app" and TIMEOUT=30 # seconds
Result
The URL keeps its quotes stripped; the trailing comment is removed from TIMEOUT

An .ini with sections

Input
[database] host = localhost
Result
{ "database": { "host": "localhost" } }

About the env and ini to json

Why config formats keep multiplying

Each of these solved the previous one's problem. Properties files gave Java a simple key-value store with escaping rules. INI added sections so one file could hold several components' settings. The .env convention stripped it back again to the flat list that maps directly onto environment variables, which is what a twelve-factor application reads.

None of them replaced the others, so a single project routinely contains all three plus JSON and YAML. Converting between them is less about preference than about moving a setting from where it is to where something else expects it.

Nesting is the thing that does not translate

JSON nests and environment variables do not. Converting the other way, a nested object has to be flattened, and the convention every framework settled on is an underscore-joined key: database.host becomes DATABASE_HOST. In .ini it becomes a section instead, which is what sections are for.

The flattening is not reversible without knowing the original shape, which is the reason the dot-splitting option exists in the other direction and is off by default. Splitting on dots turns app.name into a nested object — right if that was the intent, wrong if the key genuinely contained a dot.

Frequently asked questions

Why are values left as strings by default?
Because that is what they are. An environment variable is a string to the process reading it, and coercing types changes meaning: 0755 becomes the number 755, false becomes a boolean, and a version like 1.10 becomes 1.1. The switch is there for when the destination really is JSON, and it is off until you ask.
What happens to comments?
They are dropped, and the result says how many. JSON has no comment syntax, so the round trip works and the explanations do not survive it — worth knowing before replacing a carefully documented config file with generated output.
What makes .properties different from the other two?
Three things. A colon works as a separator as well as an equals sign, a backslash at the end of a line continues the value onto the next, and the key is everything up to the first unescaped separator — so a\=b=c is the key 'a=b' with the value 'c'. It is also the only one of the three with a written specification rather than a de facto one.
Is it safe to paste a real .env file?
The conversion runs entirely in your browser: nothing is uploaded, nothing is logged, and closing the tab discards it. That is worth stating plainly, because a real .env file is usually a list of credentials, and the honest answer to "where does this go" should never be "a server you have not heard of".