YAML Formatting Tool
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
- Paste or enter YAML data in the left input box
- Select the indent size that matches your project style
- Click 'Format' to beautify, 'Minify' to reduce size, or 'Validate' to check syntax
- View results on the right
- Click 'Copy' to copy to clipboard
Options Description
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
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: trueNested 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: productionKubernetes 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.25Convert 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: 30FAQ
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.