Shard Tools

JSON to ENV

Turn a JSON object into .env format in your browser, with keys upper-cased and values quoted where a shell needs it.

Maintained by Roshan.

Use JSON to ENV

Converts JSON into .env in this tab. Configuration files routinely hold hostnames, keys and credentials, so nothing here is sent anywhere.

Values are never retyped as numbers or booleansGuessing types is how a converter turns a postcode of 0123 into 123, or a literal string of false into a boolean. Values are carried across as they were written, and casting is left to you where it matters.

Explore developer and data tools

Find related browser-local tools for nearby tasks without starting another search.

Browse all developer and data tools

About JSON to ENV

Generating a .env file from JSON is straightforward until quoting comes up, and quoting is where a generated config breaks in ways that are hard to trace. A .env file is often sourced directly by a shell, which means a value containing a space, a dollar sign, a backtick or a quote will be interpreted rather than taken literally unless it is protected. A password containing a dollar sign that arrives at the application with a chunk missing is a genuinely difficult bug to find, because everything looks correct in the file. This converter quotes conservatively: anything containing whitespace or a character a shell treats specially gets wrapped and escaped, and everything else is left bare because unquoted is the convention and easier to read.

Work through the input

  1. Each top-level property becomes one line, with the key upper-cased and any character that is not a letter, digit or underscore replaced, since that is the conventional shape of an environment variable name.
  2. Values containing whitespace, quotes, hashes, dollar signs or backticks are wrapped in double quotes, because a shell sourcing the file would otherwise interpret them.
  3. Characters that remain special inside double quotes - the quote itself, the backslash, the dollar sign and the backtick - are escaped individually.
  4. Simple values with none of those characters are written bare, which is the usual convention and keeps the file readable.
  5. An empty value is quoted explicitly, so it reads as a deliberate empty string rather than a truncated line.

When json to env is useful

Generating a config from a settings object

Build or fetch the settings as JSON, convert, and you have a file ready to sit alongside the project.

Producing a template for a new environment

Convert with placeholder values to give a colleague the full list of variables they need to fill in.

Check the output

Questions about JSON to ENV

Why are some values quoted and not others?

Only values containing characters a shell would interpret get quoted. Leaving simple values bare keeps the file readable, which is the convention.

Why did my key change case?

Environment variables are conventionally upper case with underscores, so keys are transformed to match. The values are untouched.

Can I convert nested JSON?

Only the top level. Flatten the structure first, since .env has no concept of nesting.

What happens to arrays?

They have no representation. Join them into a delimited string before converting.

Is anything transmitted?

No. The conversion runs in this tab, which matters given what .env files usually contain.

Related tools

ENV to JSON

Turn a .env file into JSON in your browser. Handles export prefixes, quotes and inline comments.

JSON to INI

Turn JSON into an INI configuration file in your browser, with objects becoming sections.

JSON to YAML

Convert JSON into clean, readable YAML in your browser. Useful for Kubernetes manifests, CI pipelines and application config.