Oh MyUtils

YAML Formatter & Validator - Format, Minify YAML Online

Format, validate, and minify YAML configuration files with syntax highlighting and tree view. Supports Kubernetes manifests, Docker Compose, GitHub Actions — 100% client-side, your data never leaves your browser.

Indentation
Sort Keys
Off
Input
Output
 

Frequently Asked Questions

What is a YAML formatter?

A YAML formatter is a tool that takes YAML (YAML Ain't Markup Language) files and reformats them with consistent indentation, spacing, and structure. YAML is a human-readable data serialization language widely used for configuration files in Kubernetes, Docker Compose, GitHub Actions, and many other DevOps tools. Because YAML relies on indentation for structure, inconsistent formatting can make files hard to read and prone to errors. A formatter ensures your YAML files follow consistent style conventions, making them easier to read, maintain, and review in version control diffs.

How do I use this YAML formatter?

Select your desired operation using the tabs: Format, Minify, or Tree View. Paste your YAML content into the input area, upload a .yaml/.yml file, or click Sample to load an example (Kubernetes Deployment, GitHub Actions, or Docker Compose). The tool automatically validates and processes your input in real-time. Review the output in the right panel (or bottom panel on mobile). Adjust formatting options (indentation, sort keys) as needed. Click the Copy button to copy the result to your clipboard, or use Download to save the output as a .yaml file.

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

Your data is 100% safe and never leaves your browser. This YAML formatter uses the js-yaml library running entirely in client-side JavaScript. No data is transmitted to any server, stored in any database, or logged anywhere. All parsing, validation, formatting, and minification happens locally on your device. You can verify this by disconnecting from the internet — the tool works fully offline after the initial page load. This makes it safe for formatting Kubernetes secrets, CI/CD configs with tokens, database credentials, and other sensitive YAML files.

What is YAML minification?

YAML minification compresses YAML content to its smallest possible representation by converting block-style notation (indented, multi-line) to flow-style notation (compact, inline like {key: value, list: [1, 2, 3]}), removing all comments, and eliminating unnecessary whitespace. This is useful when you need to embed YAML in environment variables, pass it as a CLI argument, store it in a database field, or reduce file size for transmission. The minified output is semantically identical to the original — all data values are preserved.

What happens to YAML comments during formatting?

YAML comments (text after #) are lost when formatting because the js-yaml parser discards them during the parse step. This is a common limitation across most YAML parsers — they operate on the data model (mappings, sequences, scalars), not on the raw text. If your YAML file contains important comments, keep a backup before formatting. The data values themselves are always preserved accurately. If you only need to validate your YAML (check for syntax errors), the original text is not modified, and comments remain intact.

Why might my YAML parsing fail?

Common reasons for YAML parsing errors include: incorrect or inconsistent indentation (YAML requires consistent spaces, and the number must match between sibling elements), mixing tabs and spaces (YAML only allows spaces for indentation), unquoted special characters like colons, brackets, or braces in string values (use quotes: "value: with colon"), duplicate keys in the same mapping, invalid multi-line string indicators, and the "Norway problem" where values like no, yes, on, off are interpreted as booleans in YAML 1.1. The error message will show the exact line and column where the issue was detected.

What is the difference between YAML and JSON?

YAML and JSON both represent structured data but differ significantly. JSON uses braces {} for objects, brackets [] for arrays, requires double-quoted keys, and does not support comments. YAML uses indentation for structure, does not require quotes for most strings, supports comments with #, and has additional features like multi-line strings (| and >), anchors/aliases for data reuse, and multi-document files. JSON is strict and unambiguous, making it ideal for APIs and machine processing. YAML prioritizes human readability, making it the standard for configuration files (Kubernetes, Docker, CI/CD). However, YAML's indentation sensitivity makes it more error-prone than JSON.

Code Examples

// YAML formatting and validation using js-yaml
// Install: npm install js-yaml
const yaml = require('js-yaml');

// Validate YAML
function validateYaml(input) {
  try {
    yaml.load(input);
    return { valid: true };
  } catch (error) {
    return {
      valid: false,
      error: error.reason || error.message,
      line: error.mark ? error.mark.line + 1 : undefined,
      column: error.mark ? error.mark.column + 1 : undefined,
    };
  }
}

// Format/Beautify YAML
function formatYaml(input, options = {}) {
  const { indent = 2, sortKeys = false } = options;
  try {
    const parsed = yaml.load(input);
    const formatted = yaml.dump(parsed, {
      indent,
      sortKeys,
      lineWidth: -1,
      noRefs: true,
    });
    return { success: true, output: formatted };
  } catch (error) {
    return { success: false, error: error.message };
  }
}

// Minify YAML (convert to flow style)
function minifyYaml(input) {
  try {
    const parsed = yaml.load(input);
    const minified = yaml.dump(parsed, {
      flowLevel: 0,
      lineWidth: -1,
      noRefs: true,
    });
    return { success: true, output: minified };
  } catch (error) {
    return { success: false, error: error.message };
  }
}

// Example
const yamlStr = 'name: test\nvalue: 42\nitems:\n  - one\n  - two';
console.log('Valid:', validateYaml(yamlStr));
console.log('Formatted:', formatYaml(yamlStr));
console.log('Minified:', minifyYaml(yamlStr));

Related Tools