This repo has the one line code to either convert .env file into a json file or a json file into env
🕹️ More Cheatcodes Coming Soon
Stay updated — and if you found this useful, drop a ⭐ on the repo 😄
A clean, simple, and developer‑friendly guide for converting between .env files and JSON using shell commands. Perfect for teams, DevOps workflows, or API config management.
jq is required for JSON → ENV conversion.
for more: https://jqlang.org/download/
sudo apt install jqbrew install jqchoco install jq- Navigate to your
.envfile directory:cd /path/to/your/env - Ensure your
.envcontains valid key-value pairs. - Run the following command (unchanged from your original):
cat .env | grep -v '^#' | grep -v '^\s*$' | awk -F= '{gsub(/"/, "\\\"", $2); print "\"" $1 "\": \"" $2 "\","}' | sed '$ s/,$//' | awk 'BEGIN {print "{"} {print} END {print "}"}'IMPORTANT⚠️ : This command doesnot works directly in windows, you have to be in Git Bash, WSL, etc. terminal
If you are doing this in Powershell, here is the seperate command. Rest is same !
(Get-Content .env |
Where-Object { $_ -notmatch '^\s*$' -and $_ -notmatch '^\s*#' } |
ForEach-Object {
$parts = $_ -split '=', 2
'"' + $parts[0] + '": "' + ($parts[1].Replace('"', '\"')) + '"'
}) -join ",`n" |
ForEach-Object { "{`n$_`n}" }The resulting JSON will be printed directly in the terminal.
- Save your JSON as a file (e.g.,
input.json). - Navigate to the file directory:
cd /path/to/input.json - Run the conversion command:
jq -r 'to_entries[] | "\(.key)=\(.value)"' input.jsonIMPORTANT⚠️ : This command doesnot works directly in windows, you have to be in Git Bash, WSL, etc. terminal
If you are doing this in Powershell, here is the seperate command. Rest is same !
(Get-Content input.json | ConvertFrom-Json).psobject.Properties |
ForEach-Object { "$($_.Name)=$($_.Value)" }The .env formatted variables will be displayed directly in your terminal.
Copy & paste the output into your .env file if needed.
Easily switch between .env and JSON formats without installing heavy tools or writing scripts. Ideal for automation, CI/CD pipelines, or configuration cleanup.
Happy hacking! 🚀 Biraluu