Oh MyUtils

.env Editor - Parse, Validate, Compare & Convert Environment Files Online

Parse, validate, compare, and convert .env files with syntax checking, side-by-side diff, and format conversion between .env, JSON, YAML, and Docker Compose — 100% client-side, your secrets never leave your browser.

.env Content

Frequently Asked Questions

What is a .env file editor?

A .env file editor is an online tool that helps developers parse, validate, edit, sort, compare, and convert .env (dotenv) files. .env files store environment variables as KEY=value pairs and are used to configure applications with settings like database connections, API keys, and feature flags. This tool provides syntax validation, alphabetical sorting, side-by-side comparison of two .env files, and format conversion between .env, JSON, YAML, and Docker Compose formats — all running 100% in your browser.

How do I use this .env editor?

1. Edit tab: Paste your .env file content into the input area. The tool instantly validates it, showing errors (invalid names, missing separators) and warnings (duplicate keys, empty values). Click Sort to alphabetically order your variables, or Format to clean up the output. 2. Compare tab: Paste two .env files into the side-by-side panels (e.g., .env.development and .env.production). The tool highlights variables that are missing, extra, or have different values. 3. Convert tab: Paste content in any supported format (.env, JSON, YAML, Docker Compose), select the output format, and get instant conversion. Click Copy to copy output to your clipboard, or Download to save as a file.

Is my data safe? Does it get sent to a server?

Your data is 100% safe and never leaves your browser. All parsing, validation, comparison, and conversion happens entirely in client-side JavaScript. No environment variables, passwords, API keys, or configuration data is transmitted to any server. You can verify this by disconnecting from the internet — the tool works fully offline after the initial page load.

What validation checks does this tool perform?

The validator checks for: (1) Invalid variable names — names must start with a letter or underscore and contain only letters, numbers, and underscores. (2) Missing separator — each non-comment line must contain an = sign. (3) Duplicate keys — the same variable name appearing multiple times. (4) Empty values — keys with no value assigned. (5) Unclosed quotes — values starting with a quote without a matching closing quote. Each issue includes the line number for easy location.

How does the .env file comparison work?

The comparison tool analyzes two .env files and categorizes every variable into four groups: (1) Only in File A — variables present in the first file but missing from the second (shown in red). (2) Only in File B — variables present in the second file but missing from the first (shown in green). (3) Different values — variables present in both files but with different values (shown in yellow). (4) Identical — variables with the same key and value in both files. A summary shows counts for each category.

What formats can I convert between?

This tool supports bidirectional conversion between four formats: (1) .env format — standard KEY=value pairs. (2) JSON — a flat JSON object {"KEY": "value"}. (3) YAML — YAML key-value mapping KEY: value. (4) Docker Compose environment — the environment: list format used in docker-compose.yml. The converter auto-detects the input format and handles proper value quoting.

Can I sort my .env file alphabetically?

Yes, the Sort feature orders all variables alphabetically by key name (A-Z or Z-A). Comments are preserved and attached to the variable that follows them, so your documentation stays organized. This is useful for large .env files where finding a specific variable is difficult.

Code Examples

// .env File Parser, Validator, and Converter

function parseEnv(content) {
  const lines = content.split('\n');
  const entries = [];
  const errors = [];
  const warnings = [];
  const seen = new Map();

  for (let i = 0; i < lines.length; i++) {
    const lineNum = i + 1;
    const raw = lines[i];
    const trimmed = raw.trim();

    if (!trimmed || trimmed.startsWith('#')) continue;

    const eqIdx = trimmed.indexOf('=');
    if (eqIdx === -1) {
      errors.push({ line: lineNum, message: "Missing '=' separator" });
      continue;
    }

    const key = trimmed.slice(0, eqIdx).trim();
    let value = trimmed.slice(eqIdx + 1);

    if (!key) {
      errors.push({ line: lineNum, message: 'Empty key name' });
      continue;
    }
    if (!/^[A-Za-z_]\w*$/.test(key)) {
      errors.push({ line: lineNum, message: `Invalid name "${key}"` });
      continue;
    }

    // Handle quoted values
    if (value.startsWith('"') && value.endsWith('"')) {
      value = value.slice(1, -1).replace(/\\n/g, '\n');
    } else if (value.startsWith("'") && value.endsWith("'")) {
      value = value.slice(1, -1);
    } else {
      const commentIdx = value.indexOf(' #');
      if (commentIdx !== -1) value = value.slice(0, commentIdx);
      value = value.trim();
    }

    if (seen.has(key)) {
      warnings.push({ line: lineNum, message: `Duplicate key "${key}"` });
    }
    seen.set(key, lineNum);
    entries.push({ key, value, line: lineNum });
  }

  return { entries, errors, warnings };
}

function envToJson(entries, indent = 2) {
  const obj = {};
  for (const { key, value } of entries) obj[key] = value;
  return JSON.stringify(obj, null, indent);
}

function diffEnv(entriesA, entriesB) {
  const mapA = new Map(entriesA.map(e => [e.key, e.value]));
  const mapB = new Map(entriesB.map(e => [e.key, e.value]));
  const onlyInA = [], onlyInB = [], different = [], identical = [];

  for (const [key, valA] of mapA) {
    if (!mapB.has(key)) onlyInA.push(key);
    else if (mapB.get(key) !== valA) different.push({ key, valueA: valA, valueB: mapB.get(key) });
    else identical.push(key);
  }
  for (const key of mapB.keys()) {
    if (!mapA.has(key)) onlyInB.push(key);
  }
  return { onlyInA, onlyInB, different, identical };
}

// Usage
const result = parseEnv('DB_HOST=localhost\nDB_PORT=5432\nAPI_KEY=sk_live_abc');
console.log('Entries:', result.entries.length);
console.log('JSON:', envToJson(result.entries));

Related Tools