Data workflow guides

Convert .env to YAML and Preserve Strings

·

A YAML reader can interpret an unquoted value as a Boolean, number or null. When moving settings from dotenv, start with a mapping of strings. Then change the structure or types only where the destination application calls for them.

.env to YAML

Check the types in an inventory example

Select Load example and Convert to YAML. The generated mapping puts quotes around both keys and values. STORE_ID reads as the four-character string 0012. BIG_ID reads as 90071992547409930001, including its final digits. ENABLED reads as the string false, and EMPTY reads as a zero-character string.

The source begins with export STORE_ID. The export keyword and the opening comment are absent from the YAML because the output represents variable names and their assigned values.

Node.js dotenv syntax and string valuesYAML 1.2.2 specification, double-quoted scalars

Read the newline and hash after conversion

The GREETING value decodes as hello # team. The hash survives because it was inside quotes in the source. NOTE is a single scalar with line one, a newline, and line two. The YAML preview represents the newline as a backslash followed by the letter n. A YAML parser converts that escape to the newline character.

Remove the source quotes around GREETING and convert again. The greeting becomes hello because the hash outside quotes starts a comment. Restore the quotes to preserve the full greeting.

Node.js dotenv syntax and string valuesYAML 1.2.2 specification, double-quoted scalars

Load the downloaded mapping in your destination

Download the YAML and reopen it with the same YAML parser your project uses. Check that STORE_ID and BIG_ID have all their digits and that NOTE is one value with two lines. Keep the quotes if you edit the YAML by hand.

If the target expects an environment section, place the exported keys inside that section. If conversion stops on a duplicate name, decide which source assignment should supply the value, remove the other assignment and convert again.

YAML 1.2.2 specification, double-quoted scalarsNode.js dotenv syntax and string values

Common questions

Will a value such as ${HOME}/cache be expanded?

It is copied as literal text. Expansion is a separate behavior that depends on the destination application.

Can the output keep comments from .env?

The YAML export is a mapping of assigned names and decoded values. A hash inside a quoted value survives. Source comments are omitted.

Sources

Put it into practice.

Related guides