ToolActToolAct

YAML Formatting Tool

Input YAML
Output
Lines: 1Characters: 0Bytes: 0
Lines: 1Characters: 0

What is YAML?

The YAML Formatter makes YAML files easier to read by applying consistent indentation, line breaks, and visible structure. YAML is widely used for CI configuration, Kubernetes manifests, Docker Compose, static-site generators, localization, OpenAPI files, and application settings. Unlike JSON, YAML depends heavily on indentation, list markers, colons, quoting, anchors, and multiline strings; a small formatting mistake can create a different structure from the one intended. This tool helps read, clean up, and spot obvious syntax issues, but it does not replace schema validation or tool-specific checks. For Kubernetes, GitHub Actions, Ansible, or production configuration, the formatted output should be tested in the target system.

How to Use

How to use

  1. Paste or enter YAML data in the left input box
  2. Select the indent size that matches your project style
  3. Click 'Format' to beautify, 'Minify' to reduce size, or 'Validate' to check syntax
  4. View results on the right
  5. Click 'Copy' to copy to clipboard

Options Description

Indent SizeChoose between 2 spaces or 4 spaces indentation

Keyboard Shortcuts

  • Ctrl + EnterFormat
  • Ctrl + Shift + CCopy result

YAML Tips

  • YAML is indentation-sensitive, so review nested lists and maps after formatting before using the result in CI, Kubernetes, or deployment files.
  • Validate against the target tool's schema when possible; syntactically valid YAML can still be invalid for GitHub Actions, Docker Compose, or OpenAPI.

Use Cases

Normalize simple YAML configuration before committing itPaste application, server, database, feature-flag, logging, or user-role YAML and format it with either 2-space or 4-space indentation. The tool is aimed at everyday key-value, nested-object, array, boolean, number, null, and quoted-string structures.
Spot common YAML spacing mistakes quicklyThe built-in validator flags lines without a colon separator, values missing the required space after a colon, and tabs used where spaces are required. That catches many copy-paste and hand-editing mistakes before the file reaches a CI parser, deployment script, or documentation page. Parsing and validation happen entirely in the browser, so a draft manifest containing internal service names, unreleased image tags, or staging credentials can be cleaned up without uploading the file to a remote validator.
Create a clean downloadable YAML sample from a messy draftAfter parsing, the formatter rewrites the object tree into consistent YAML and lets you copy or download formatted.yaml. It uses a lightweight parser rather than a full YAML engine, so anchors, aliases, complex multiline scalars, tags, and advanced schema behavior should still be checked with the runtime that will consume the file.
Convert YAML to JSON for a downstream pipelineUse the toggle to switch the output to JSON while keeping the same indentation choices, so CI scripts, jq filters, or policy checks can consume the file without a second parser. Mixed-type arrays and quoted strings stay intact, but YAML anchors and aliases are still flattened by the lightweight parser.
Pre-flight a Kubernetes or Docker Compose manifestDrop in a deployment.yaml or docker-compose.yml, fix the spacing errors the validator flags, and confirm the apiVersion, kind, and spec blocks line up. The page is a quick read-and-clean step, but the final manifest still needs kubectl apply --dry-run=client or docker compose config to catch schema issues.

Technical Principle

YAML formatting is anchored to the YAML 1.2.2 specification (revised October 2021), which formally defines JSON as a strict subset of YAML - any valid JSON document is parseable as YAML. Parsing proceeds in three layers: a presentation layer scans Unicode code points and resolves character escapes; a serialization layer constructs a node graph of scalars, sequences and mappings; a native layer applies the YAML Core Schema to coerce scalars into the resolved types `!!str`, `!!int`, `!!float`, `!!bool`, `!!null`, `!!seq`, `!!map`. Common runtime libraries include js-yaml and the newer `yaml` package on Node, PyYAML and ruamel.yaml on Python, and SnakeYAML on the JVM. Browser-side formatters typically parse into a plain JS object via js-yaml's `load`/`dump` and round-trip. Indentation is the load-bearing primitive: only ASCII space (U+0020) is permitted - the spec explicitly forbids tab characters (U+0009) for indentation in §6.1, which is why pasting from a code editor that auto-converts is the single most common parse failure. Block style determines nesting purely from column position, so child nodes must be indented more than their parent by at least one space (two by convention). Flow style borrows JSON syntax - `[1, 2, 3]` and `{a: 1, b: 2}` - and can be nested inside block style for one-liners. Block scalars use indicator-driven folding: `|` (literal) preserves newlines exactly, `>` (folded) collapses single newlines into spaces and keeps blank lines as paragraph separators, and the chomping indicators `-` (strip trailing newlines) and `+` (keep all trailing newlines) attach after the indicator (`|-`, `>+`). Quoting rules differ: single-quoted scalars treat `\` literally and use `''` to embed a quote; double-quoted scalars honor C-style escapes (`\n`, `\t`, `\uXXXX`). Formatters typically normalize to one block style and re-emit anchors and aliases. An anchor `&name` marks a node; an alias `*name` references it; the merge key `<<: *name` (a YAML 1.1 holdover still supported by most parsers) pulls keys from another mapping into the current one. Multi-document streams are split by `---` start markers and optional `...` end markers, the pattern used by Kubernetes to ship many resources in one manifest. Two well-known footguns are worth re-emitting safely: the Norway problem - the unquoted scalar `no` is interpreted as `false` under the YAML 1.1 schema (and the country code becomes a boolean) - and CVE-2017-18342, where PyYAML's `yaml.load` deserialized arbitrary Python objects, fixed by switching to `safe_load`. Both are reasons a formatter should treat scalar resolution carefully and never execute tagged constructors. Parsing is O(n) over input length; comments are discarded by most AST-based libraries because they are not part of the YAML information model.

  • Spec: YAML 1.2.2 (Oct 2021). JSON is a strict subset of YAML 1.2, so any valid JSON document parses as YAML; common libs are js-yaml, the `yaml` package, PyYAML, ruamel.yaml, SnakeYAML.
  • Indentation must be ASCII space (U+0020); tab characters (U+0009) are forbidden for indentation by §6.1 - the single most common cause of `mapping values are not allowed here` errors.
  • Block vs flow style: block uses column-position nesting (2 or 4 spaces by convention); flow uses JSON-like `[1, 2, 3]` and `{a: 1}`. Both can nest.
  • Block scalars: `|` literal preserves newlines, `>` folded collapses single newlines to spaces; chomping indicators `-` (strip) and `+` (keep) attach to the indicator, e.g. `|-`, `>+`.
  • Anchors `&name` mark nodes, aliases `*name` reference them, and the merge key `<<: *name` pulls keys from another mapping (YAML 1.1 holdover, supported by most parsers).
  • Multi-document streams split by `---` (start) and optional `...` (end) markers - the pattern Kubernetes uses to ship multiple resources in one manifest.
  • Footguns: the Norway problem (unquoted `no`/`yes`/`on`/`off` parsed as booleans under YAML 1.1 schema; YAML 1.2 Core Schema fixes most of this) and CVE-2017-18342 (PyYAML `yaml.load` arbitrary code execution; use `safe_load`).

Examples

Fix inconsistent indentation in a config file

Input (broken):
server:
   port: 8080
     host: localhost
  debug: true

Formatted (2-space):
server:
  port: 8080
  host: localhost
  debug: true

Nested list of services in docker-compose.yml

version: '3.8'
services:
  web:
    image: nginx:1.25
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - api
  api:
    image: node:20
    environment:
      NODE_ENV: production

Kubernetes Deployment manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  labels:
    app: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    spec:
      containers:
        - name: web
          image: nginx:1.25

Convert YAML to JSON for a jq pipeline

YAML input:
user:
  id: 42
  name: alice
  roles:
    - admin
    - editor

JSON output:
{
  "user": {
    "id": 42,
    "name": "alice",
    "roles": ["admin", "editor"]
  }
}

Catch a missing space after colon

Input:
name:alice
age: 30

Error at line 1: missing space after colon
Fixed:
name: alice
age: 30

FAQ

What does YAML formatting cover?

Indentation normalization (typically 2 spaces), consistent quote style, list-marker alignment, and re-flowing long inline collections into block style. Most YAML in the wild is hand-edited and accumulates inconsistent style; the formatter levels it out.

Will it convert flow style to block style?

Many builds let you choose between flow style (JSON-like {key: value, key2: value2}) and block style (multi-line indented). Block is more readable for human editing; flow is more compact. Round-tripping between them preserves data but changes appearance.

Why does it change my quotes?

YAML allows unquoted, single-quoted, and double-quoted strings with subtle differences. Yes/no, true/false, on/off are interpreted as booleans unless quoted; numbers without quotes are numbers, with quotes are strings. The formatter may add quotes to disambiguate values that would be misinterpreted otherwise.

Does it preserve comments?

Most builds preserve YAML comments (#) but their position relative to AST nodes may shift slightly. Comments above keys usually stay above; trailing comments on the same line stay attached. Reload after formatting and check if the comment placement still makes sense.

Is the YAML uploaded?

No. Parsing and formatting run in your browser via js-yaml or similar. Pasted YAML is not transmitted.

Why does my YAML round-trip change anchors and aliases?

YAML's & (anchor) and * (alias) syntax lets you reference a value once and reuse it. Some formatters expand aliases inline by default, losing the deduplication. Look for an option to preserve anchors if your tooling depends on them.

What if my YAML has tab indentation?

YAML forbids tabs for indentation - they must be spaces. The formatter typically converts tabs to spaces or refuses to parse depending on configuration. Replace tabs with spaces before pasting if you hit a parse error.